-
In certain situation in programming, statement(s)
are required to be repeated for fixed number of times or till certain condition
is satisfied.
-
C language provides looping structures so that we
need not to write those statement(s) again and again in our program. If the
language does not provide looping structures then we will have to write those statement(s) again and again in our program.
language does not provide looping structures then we will have to write those statement(s) again and again in our program.
-
And the program will becomes very lengthy,
unmanageable and more typing.
-
In that case, we will have no option. But C language
provides the looping structures for those cases.
Looping Structures are:
1.
while loop,
2.
do…while loop,
3.
for loop.
Types of loops
- There are two types of loop structures depending on
where the condition is checked.
1. Entry control loop
2. Exit control loop
1. Entry control loop
-
In entry control loop, the condition is written
first and checked. Till the condition is true, it will execute the body of
statement(s).
-
While loop is entry control loop.
-
Flow chart
while loop |
2. Exit control loop
-
In exit control loop, the body of statement(s) is
written first and then condition is written.
-
This means that body of statement(s) in exit control
loop will be executed at least once.
- do...while loop is exit control loop
-
Flow chart:
do ... while loop |
No comments:
Post a Comment