do-while loop

We have already seen while loop for C programs. "do-while" is similar to while loop, except the position of the condition to be tested. If you have not learnt while loop yet, please click here.

If you are done with while loop you would know that, in C programs while loops are used when we know in prior that how many times the loop has to be executed. But what if we don't know how many times do we need to execute the loop? "do-while" is used in such cases.

In do while loop, the logic portion is executed once even if condition becomes false at first test itself. This can be easily understood from syntax given below.  

No comments:

Post a Comment