CSC215,ScheduleSyllabus,
C++, Matlab
Guidelines,Evaluations

 

Various Forms of if and else Statements

if without else

if (something is true)
{

do something or

}
continue with program

 

if with else

if ( something is true)
{

do something;

}
else
{

do something different;

}



Nested if Statements

if ( something is true)
{

if (something different is true)
{

do something

}
else
{

do something different

}

}
else
{

if (another thing is true)
{

do something;

}
else

{

do something different

}

}

else if Ladder

if (first condition is true)
{

Do first option

}
else if (second condition is true)
{

Do second option

}
else if (third condition is true)
{

Do third option

}
else
{

Do this when all the above are false.

}

switch/case Similar to else if Ladder

switch (expression)
{

case value1:

statement1;
statement2;
break;

case value2:

statement3;
statement4;
break;

case vulue1:

statement1;
statement2;
break;

Default:

Do when no case is selected