Control structures in C Programming by TK
Control structures in C Programming by TK
true
condition? statement
false
true false
condition?
statement-1 statement-2
switch
Test variable for multiple values
Series of case labels and optional default case
switch ( variable ) {
case value1: // taken if variable == value1
statements
break; // necessary to exit switch
case value2:
case value3: // taken if variable == value2
or == value3
statements
break;
true
case a case a action(s) break
false
true
case b case b action(s) break
false
.
.
.
true
case z case z action(s) break
false
default action(s)
true
condition? statement
false
• Break
– Causes immediate exit from a while, for,
do/while or switch structure
– Program execution continues with the first
statement after the structure
– Common uses of the break statement:
• Escape early from a loop
• Skip the remainder of a switch structure
• Continue
– Skips the remaining statements in the body of a while,
for or do/while structure and proceeds with the next
iteration of the loop
– In while and do/while, the loop-continuation test is
evaluated immediately after the continue statement is
executed
– In the for structure, the increment expression is
executed, then the loop-continuation test is evaluated