Comparison of Loops

WhileUntilFor
C syntax
while (expression)
   statement;
       

while (expression)
{
   statement(s);
}
C syntax
do
   statement;
while (expression);


do
{
   statement(s);
}
while (expression);
C syntax
for (initialize; compare; increment)
   statement;


for (initialize; compare; increment)
{
   statement(s);
}
General - logically controlled loop General - logically controlled loop Restricted - counter controlled loop
Comparison at topComparison at bottom Comparison at top and is part of the syntax of the loop
Executes 0 or moreExecutes 1 or more Executes 0 or more
1 or more Loop Control Variables1 or more Loop Control VariablesONE Loop Control Variable
Loop Control Variables can be any data type Loop Control Variables can be any data type Loop Contral Variable is of an integral type (integer, character)
One or more compound comparisons One or more compound comparisons One comparison - either <= or >= depending on whether counting up or down
Any legal statement may be used to change the value of the loop control variableAny legal statement may be used to change the loop control varialbeThe loop control variable is incremented or decremented by a fixed amount as part of the syntax of the loop
Every until loop and every for loop can be written as a while Every while loop and every for loop can be written as an until Only some while loops and until loops can be written as for loops