Last updated on June 13th, 2020 at 08:26 pm
Comparison among the three loop:
The comparison among the three types of loops for loop, while loop and do….while loop is given below.
Suggested Reading:
No. | Topics | For loop | While loop | Do…while loop |
01 | Initialization of condition variable | In the parenthesis of the loop. | Before the loop. | Before the loop or in the body of the loop. |
02 | Test condition | Before the body of the loop. | Before the body of the loop. | After the body of the loop. |
03 | Updating the condition variable | After the first execution. | After the first execution. | After the first execution. |
04 | Type | Entry controlled loop. | Entry controlled loop. | Exit controlled loop. |
05 | Loop variable | Counter. | Counter. | Sentinel & counter |
Also the following comparison of their structures completes the comparison.
For loop | While loop | Do….while loop |
for(n = 1; n <= 10; n++) { ======== ======== } | n = 1; while(n <=10) { ========== ========== n=n+1; } | n = 1; do { ======== ======== n = n + 1; } while(n<=10); |