Loop statements are used to perform the same action, or variations of the same action, multiple times in a row. As such, they form an important part of every programming language.
Oxygene provides four core types of loops:
forloops iterate over a given set of data, be it a sequence of objects or a range of numbers with a well-defined start and end point.
doloops keep iterating while a certain condition is true, re-evaluating the condition each time the loop begins. They might run zero or more times.
untilloops keep iterating until a certain condition is false, re-evaluating the condition each time the loop ends. They always run one or more times.
looploops, also referred to as Infinite Loops, run indefinitely, until they are broken out of using either a
Loop statements can be prefixed with an optional name, separated form the loop keyword by a colon. When such a name is provided, it can be used in
break flow control statements to more precisely control which loop to cpntinue or break out of.
var i := 0; lOuterLoop: while i < 30 do begin i := i + 1; for j := 0 to 20 do begin if i*j = 150 then continue lOuterLoop; // contine the OUTER loop writeLn(i*j); end; writeLn(i); end;
- Labeled loop statements are new in Version 8.2.