- The natural sequential execution of a C prog
- Changing order of execution is a need
- Repeating a group of statement until specified conditions are met is also a need
- The Control or Decision Making statements
- If, switch, Conditional Operator statement, goto statement
if Statement
- if (condition) {statement block}
- if (condition) {true statement block} else {false statement block}
- Nested if is possible
- if (condition1) {statement block} else if (condition2) {statement block2} else if (condition3) {statement block3} …
Switch Statement
It’s a multi-way decision making statement
switch (expression)
{
case value1:block1
break;
case value2:block2
break;
…..
default: blockn
}
Example
index = marks/10
switch(index)
{ case 10:
case 9:
case 8:
case 7: printf (“Distinction”)
case 6: printf (“First Class”)
case 5: printf (“Second Class”)
case 4: printf (“Third Class”)
default: printf (“Fail” }
Conditional Operator and goto
- if (x<0) flag = 0; else flag = 1; is equivalent to flag = (x<0) ? 0 : 1
- Nested operations are possible
- goto Initiate_it; is a statement directs control to label Initiate_it:
- It’s unconditional branching
- It’s only advised to be be used in specific conditions