184 Programming and Data Structures
i++;
}
printf ("tt Outer Loop (i) Completed ");
OUTPUT:
i=lj= l k=l
Inner Loop (k) Completed.
i=l j=2 k=l
Inner Loop (k) Completed.
Middle Loop (j) Completed.
i=2 j=l k=l
Inner Loop (k) Completed.
i=2 j=2 k=l
Inner Loop (k) Completed.
Middle Loop (j) Completed.
i=3 j=l k-1
Inner Loop (k) Completed.
i--3 j~2 k=l
Inner Loop (k) Completed.
Middle Loop (j) Completed.
O uter Loop (i) Completed.
Explanation In the above program variable i , j # & k are declared and initialized to 1. The inner
most loop is ' k ', the middle is ' j 7 and the outer most is ' i ' . The execution of loop starts from outer
to inner and the completion will be from the inner most to the outer most. Here, for example the values
of i , j & k are printed and messages are printed to understand the termination of loops.
6.5 THE do-while
The format of do-while loop in C is as follows.
do
(
statement/s;
}
while (condition);
The difference between thewhile and do-while loop is in the place where the condition is to be tested.
In the while loops the condition is tested following the w hile statement and then the body gets
executed. Where as in the d o-w h ile, the condition is checked at the end of the loop. The do-while
loop will execute at least one time even if the condition is false initially. The do whi le loop executes
until the condition becomes false.