Loop Statements

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:

  • for loops 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.
  • while/do loops keep iterating while a certain condition is true, re-evaluating the condition each time the loop begins. They might run zero or more times.
  • repeat/until loops keep iterating until a certain condition is false, re-evaluating the condition each time the loop ends. They always run one or more times.
  • loop loops, also referred to as Infinite Loops, run indefinitely, until they are broken out of using either a break, exit or raise statement.

Labeled Loops

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 continue and 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

Version Notes