Professional Documents
Culture Documents
Session 7
Control Structures
If For Break
If LAdder
Nested If
Switch
Decision Making Statements
Session 7 a
If Statement
False
– or else if the condition is
false, the statements are
not executed but
remaining program will
continue.
If .. Else..
• Syntax:
if (cond )
{
False True
statements-1; Cond?
}
Statements-1 Statements-1
else
{
statements-2;
}
If Ladder
• Syntax:
if(cond-1) • This will check if cond1 is
true or not
{
• If cond1 is true then
statements-1; statements1 will be
} executed
else if (cond-2) • Else cond2 is checked
{ • If cond2 is true
statements-2; statements 2 are
} executed
.… • Else cond3 …. To any
number of conditions
….
• If no condi9tion is true the
else else statements are
{ executed.
Statements;
}
Nested IF
• Wrting an if inside another if is called the nested if
• Unless the first cond is true the next condition is not
checked.
• C allows 32 levels of nesting at maximum.
• Syntax:
if(cond1)
{
if(cond2)
{
….
}
}
Switch Statement
stop True
For Loop
Inc / dec
Non Conditional Control Statements
Break()
Goto label
Continue()
Exit()
label
The goto statement transfers control to any other
statement within the same function in a C program.
It actually violates the rules of a strictly structured
programming language.
They reduce program reliability and make program
difficult to maintain.
statement
The break statement is used to terminate a case in a
switch statement.
It can also be used for abrupt termination of a loop.