170120107074 looping statements and nesting of loop statements
1. 1
Gandhinagar Institute Of Technology
Subject: CPU (2110003)
Looping Statements, Nesting of Loop Statements
Prepared by: Tarj Mehta
Enrollment No: 201707000179
Guided by- Mrs.Hetal Shah
2. 2
What is Looping?
●
Repeating the same path again and again is called
looping.
●
The same path is repeated till the desired output is
obtained.
●
A simple life problem of looping can be understood by
example of searching the name from telephone directory
and repeating the process letter by letter till the desired
name is obtained.
3. 3
What is Looping in C?
●
In C programming, looping is a sequence of instructions
that is continuously repeated until a certain condition is
reached.
●
The programming is done is such a way that certain
conditions are checked.
●
If the conditions are satisfied, then only output is
obtained.
4. 4
Why is looping used?
●
If we want to print ‘HI’ 100 times it is not a willing work to
implement ‘printf’ command 100 times.
●
There are more chances to make mistake.
●
If any error is found, it is very boring job to search for it
in 100 printf commands executed.
●
Thus to save time and mistake looping is used.
5. 5
Types of Loop Statements in C
●
Loop provides a way to repeat command and control
how many times it is repeated.
●
Types of loop:
1. For
2. While
3. Do...while
7. 7
For Loop
●
For loop is called entry control
loop as it checks the condition
while entering the loop.
●
The loop is repeated till the
given condition is satisfied,
once the condition is not
satisfied the loop is terminated
and program comes to next
statement.
9. 9
While Loop
●
While loop is also called
entry control loop as it
checks the condition during
entering the loop.
●
Once the condition is
satisfied, loop is executed
and the printf statement in it
is executed and incr/decr is
done for next condition
checking.
11. 11
Do.....while Loop
●
Do...while loop is also
known as exit control loop
as the condition is
checked during exit of
loop.
●
In false condition also the
output statement is
printed atleast once.
12. 12
Nesting of Loop Statements
●
Loop within a loop is called Nested loop and this action
is called Nesting of loop statements.
●
One loop is kept inside the body of first loop.
●
Number of nested loops are also possible.
14. 14
Example of Nested loop
●
The nesting of loop is
executed when condition
of first loop is true.
●
The outer loop takes
control of number of
complete repetitions of
inner loop.
●
The most common nested
loop is ‘for’ loop.
15. 15
Conclusion
●
Looping saves time.
●
It is easy to execute.
●
It decreases the possibilities of mistakes while
programming.
●
Nesting of loop allows us to write more complex
programs.