



In the example above, the variable i is declared before the loop, and continues to exist after the loop has completed.However it can be any legal C/C++ statement, such as "N += 3" or "counter = base + delta". The third part of the loop is labeled "incrementation", because it usually takes the form of "i++" or something similar.

for-loops are counter-controlled, meaning that they are normally used whenever the number of iterations is known in advance.Note that once you enter the loop, the operation is identical from that point forward: The following diagram shows the difference between while and do-while loops.Note that the above example could be improved by reporting to the user what the problem is if month is not in the range 1 to 12, and that it could also be done using a while loop if month were initialized to a value that ensures entering the loop.Where the body can be either a single statement or a block of statements within. While loops check for the stopping condition first, and may not execute the body of the loop at all if the condition is initially false.Both while and do-while loops alternate between performing actions and testing for the stopping condition.Both while loops and do-while loops ( see below ) are condition-controlled, meaning that they continue to loop until some condition is met.while Loops ( Condition-Controlled Loops ) In this section we will learn how to make computer repeat actions either a specified number of times or until some stopping condition is met. C Programming Course Notes - Looping ConstructsĬomputers are very good at performing repetitive tasks very quickly.
