Type of Loop in C Programminig
Type of Loop
We can classify
the loop into two categories. They are:
1].
Pre-Tested
Loop :
When the control statement is placed
at the beginning/top of the loop body is called Pre-Tested or Entry Controlled
loop.
These
types of loop first check the given condition then execute the body of a loop.
Counter=Start
Value
{
Statement
1
.
. . . . . . . .
Statement N
Counter Update
}
Example: -
for loop, while loop
2].
Post-Tested
Loop :
When the control statement is placed
at the end/bottom of the loop body is called Post-Tested or Exit Controlled
loop.
This
type of loop first executes the body of a loop then check the given condition.
Counter=Start Value
{
Statement
1
.
. . . . . . . .
Statement N
Counter Update
}
(condition)
Example: - do…while loop
The execution of
loop includes the following four steps:
1].
Initialize the loop variable.
2].
Test the condition using loop variable
with the end value.
3].
Execute the statements within the loop
body.
4].
Update the loop variable.
Types Of C Language Loop:- An Introduction
C language
provide following three types of loop statements:
1].
while Loop
2].
2].for
Loop
3].
3].do…while
Loop
Comments
Post a Comment