Report Writing On Loops
Report Writing On Loops
Seminar Report On
“Loops In C Programming”
Presented By:
How it works
The Below diagram depicts a loop execution,
Loop Entry
Test false
running…… Conditi
on
?
true
Execute
loop
Out of loop
As per the above diagram, if the test condition is true, then the loop is
executed, and if it is false then the execution breaks out of the loop. After the
loop is successfully executed the execution again starts from the loop entry
and again checks for the test condition, and this keeps on repeating.
The sequence of the statement to be executed is kept inside the curly braces {}
known as the loop body. After every execution of bod, condition is verified,
and if it is found to be true the loop body is executed again. When the condition
check returns false, the loop body is not executed, and execution
Breaks out of the loop.
Types of Loop
Exit Controlled Loops: In this type of loops the test condition is tested or
evaluated at the end of loop body. Therefore, the loop body will execute at
least once, irrespective of whether the test condition is true or false. do –
while loop is exit controlled loop.
For Loop
A for loop is a repetition control structure which allows us to write a loop that
is executed a specific number of times. The loop enables us to perform n
number of steps together in one line.
Syntax:
In for loop, a loop variable is used to control the loop. First initialize this loop
variable to some value, then check whether this variable is less than or greater
than counter value. If statement is true, then loop body is executed and loop
variable gets updated . Steps are repeated till exit condition comes.
Output :-
While Loop
While studying for loop we have seen that the number of iterations is known
beforehand, i.e. the number of times the loop body is needed to be executed is
known to us. while loops are used in situations where we do not know the
exact number of iterations of loop beforehand. The loop execution is
terminated on the basis of test condition.
Syntax:
initialization expression;
while (test_expression)
{
// statements
update_expression;
}
Flow Diagram:
Example :- Program to print “hello world” 10 times.
Output :-
do while loop
In do while loops also the loop execution is terminated on the basis of test
condition. The main difference between do while loop and while loop is in do
while loop the condition is tested at the end of loop body, i.e do while loop is
exit controlled whereas the other two loops are entry controlled loops.
Note: In do while loop the loop body will execute at least once irrespective of
test condition.
Syntax :-
initialization expression;
do
{
// statements
update_expression;
}
while (test_expression);
Flow Diagram:
Example :- Program to print “hello world” 10 times.
Output :-
Jumping Out of Loops
1) Break Statement :-
2) Continue Statement :-
It causes the control to go directly to the test-condition and then continue the
loop process. On encountering continue, cursor leave the current cycle of
loop, and starts with the next cycle.