Control Statement
The control statement are used to create special program features such as Decision making statement, Iterative
statement and Jumping statement.
Decision Making Statement / Selective / Branching Statement
if
The "if" statement is a powerful decision making statement which is used to execute a block of statement base
on whether the given test condition is true or false.
If the condition is true, the block of statement will be executed, otherwise it will be skipped.
if else
The "if else" statement is simply an extension of if statement which is used to execute the true block
statement or false block statement depending upon the test condition.
nested if else
The "nested if else" statement is simply an extension of if else statement which is obtained by using an if
else decision statement within another if else decision statement.
if else ladder
The "if else ladder" helps user decide from among multiple options which is executed from the top down. As
soon as one of the conditions is true, the statement associated with that if is executed, and the rest of the
else-if ladder is bypassed. If none of the conditions is ture, then the final else statement will be execute.
Switch statement
Switch statement allows a programmer to choose a particular block of statements from several blocks of
statements.
Iterative Statement
Iterative statement or loop statement in C program causes a section of program to be executed repeatedly until
some logical condition has been satisfied is known as loop.
for loop
The for loop is used to execute a statement for fixed number of times.
while loop
- The while loop is used to execute a statement for unknown number of times.
- The while loop is called top tested loop as the test expression is at the beginning of the program.
- The body of the loop is executed only if the test condition is true.
do - while loop
- The do while loop is used when one is sure about the test condition
- The do while loop is also called botton tested loop as the test expression is at the bottom of the
loop.
- The body of the loop is executed at least once even if the test condition is false.
Entry Control loop |
Exit Control loop |
Entry Control loop checks condition first and then body of the loop will be executed. |
The exit control loop first executes the body of the loop and checks condition at last. |
The body of the loop may or may not be executed at all. |
The body of the loop will be executed at least once because the condition is checked at last. |
for, while are an example of an entry control loop. |
Do... while is an example of an exit control loop. |
BREAK
- The break statement is used to terminate or to exit or to jump out of the loop or switch statements.
- It can be used within a for, while, do-while or switch statement.
CONTINUE
- Whenever the continue statement is encountered the remaining portion of the loop after the continue is
skipped out and proceeds directly to the next pass of the loop.
- The loop won't be terminated when a continue statement is encountered.
GOTO
- The goto statement alters the normal sequence of program execution by transferring control to some other
parts of program.
- Basically it is used for jumping, to any part of the program from any position.
EXIT() FUNCTION
- The exit function is expecially used to terminate or to exit from the entire loop and program as a
whole.
- Thus, whenever the exit() function is encountered, the program execution is brought to an end.
- It can be included at any position in the program body.