2. Loop Statement are used to repeat
the execution of statement or
blocks.
Two types of loop structure are:
Pretest
Posttest
3. Pretest versus Postest
Pretest: Condition is tested before each iteration to
check if loop should occur.
Example: For and While Loop
Posttest: Condition is tested after each iteration to
check if loop should occur.
Example: Do-While Loop
4. For Loop
For Loop has three parts:
Initializer is executed at start of loop.
Loop condition is tested before iteration to decide
whether to continue or terminate the loop.
Increment is executed at the end of each loop
iteration.
6. While Loop
It has a loop condition only that is tested before
each iteration to decide whether to continue or
terminated the loop.
Syntax:
while(<condition>)
<statement/block>;
8. Do-While Loop
Do-While has a loop condition only that is tested
after each iteration to decide whether to continue
with next iteration or terminate the loop.
Syntax:
do
<statement/block>;
while(condition);