3. LOOPING
• Looping is the process of repeatedly executing
a block of statements until some conditions
for the termination of the loop are satisfied.
• Two types of loop structure are:
• 1) pretest
• 2) posttest
4. Pretest v/s posttest
Pretest
• Condition is tested before
each iteration to check if
loops should occur.
• eg: For & while loop.
Posttest
• Condition is tested after
each iteration to check if
loops should continue (at
least a single iteration
occurs).
• Eg: do while loop.
5. The while statement
• It is an entry-controlled loop statement. The
test condition is evaluated and if it is true, the
body of the loop is executed. After execution
of the body, the condition is again evaluated
and if it is true, the body of the loop is
executed again. This process continuous until
the test condition becomes false and the
control is transferred out of the loop.
8. The do_while statement
• It is an exit controlled loop statement. The body of
the loop of do statement is compulsorily executed
for the first time. After executing once., at the end of
the loop, the test condition in the while statement is
evaluated. If the condition is true, the body of the
loop is executed again and this process continuous
until the condition becomes false, the loop execution
is terminated and the control goes to the statement
that appears after the while statement.
11. The for statement:
• It is also an entry-controlled loop.
• All for loops are executed in following
sequence.
• 1] it executes initialization statements
• 2] it check the test condition if true than go to
step:3 other wise step 4.
• 3] execute body of loop and go to step 2 after
increment or decrement
• 4] other statement of the program.
13. •Different ways of using for loop:
•More than one variable can be initialized in the for loop.
For(p=1, n=0; n<4; ++n)
•The increment section may contain more than one part.
For(p=1,n=0; n<4; ++n, ++p)
•You can either do increment or decrement.
For(n=4; n>0; -n)
•You can also omit one or more sections in the for loop.
For( ; n<4; )