View Full Version: else if

C++ Learning Community > C++ Tips > else if


Title: else if
Description: more compact way to do it


ih8censorship - June 22, 2003 01:48 PM (GMT)
ok say you want to have a list of things to printo to the screen or whatever if certain conditions are met and you want only one. you could write:

if something=5
do.something
else
if something=10
do.somethingelse


but the easyer way to do that would be:
if something=5
do.something
else ifsomething=10
do.somethingelse


and say you wanted to do several things you could put those actions or whatever there called into braces like:

else if something=10
{
do.somethingelse
do.anotherthing
do.andanother
}



well thats what i have learned lately pretty good since i only started reading the second chapter i guess. oh yeah thats not really c++ its just simulated code or psudecode. so dont try to compile exactly that or you will get a ton of error messages ;)




* Hosted for free by InvisionFree