In programming languages, iteration statements are extensively used. They cause statements to be executed zero or more times, subject to loop-termination criteria.

C and C++ provide three iteration statements: for, do and while. Each of these iterates until its termination expression evaluates to false, or until loop termination is forced with a break statement. The exact syntax, which you can also encounter in other languages such as Java, Perl and scripting languages like PHP and JavaScript:

for (i = 0; i < 5; i++) 
{
(statement)
}


do
{
(statement)
}
while (i < 5);


while (i < 5)
{
(statement)
}

The differences: for and while evaluate the termination expression at the top of the loop, whereas do does this at the end. Contrary to while, for can contain initialization values and incrementations (in the while statement, you would have to include these in the statement that is iterated).

Visual Basic also includes these three iteration statements. Of course the syntax is somewhat different:

For i = 0 To 5
(statement)
Next i


Do
(statement)
While i < 5


While i < 5
(statement)
Wend

In this case, Pascal is reasonably similar to these languages. Pascal programmers will have recognized the while and for-statements. In this language, the third option is repeat... until (Delphi knows the for, repeat and while as well. The syntax is similar to Pascal's):

for i := 0 to 5 do begin
(statement)
end;


repeat
(statement)
until i = 5;


while i < 5 do begin
(statement)
end;

As far as I know, in Cobol you can make use of PERFORM in combination with TIMES or UNTIL to make an iteration. Adding WITH TEST BEFORE (the default) or WITH TEST AFTER to the UNTIL-statement makes it equivalent to the while and do respectively that we've seen above in other languages. The syntax would look something like:

PERFORM 5 TIMES
(statement)
END-PERFORM

PERFORM WITH TEST AFTER UNTIL EndOfFile
(statement)
END-PERFORM

Cobol also knows a PERFORM... VARYING statement that is quite similar to the for-statement.

It`er*a"tion (?), n. [L. iteratio.]

Recital or performance a second time; repetition.

Bacon.

What needs this iteration, woman? Shak.

 

© Webster 1913.

Log in or register to write something here or to contact authors.