Control Statements in C :
if-else : The if block is executed when the condition is true otherwise else block is executed.
syntax:
if (condition)
{
syntax:
if( condition)
// statements
else if( condition)
//statements
else if(condition)
//statements
else
//statements
Example:
switch : It is similar to the switch case statement where the default is executed instead of else block if none of the cases is matched.
syntax :
switch (value)
{
case 0 : // statement 1
break;
case 1 : // statement 2
break;
case2 : // statement 3
break;
default : //stattement 4
break;
}
Flow Diagram:
Example:
Output:
Explanation: The value 10 matches at the 2nd case. The value doesn't matches with the 3rd case and default case because of the break statement in the second case. If there is no break statement in 2nd case the following cases will execute until the break statement found.
prev<---operators next topic --->Iterators in c
No comments:
Post a Comment