WHILE

Function

Begins a WHILE ... END-WHILE loop.

Syntax

WHILE logical_expression

The general format of WHILE is as follows:

WHILE logical_expression
SQR_commands...
[BREAK]
[CONTINUE]
SQR_commands...
END-WHILE

Arguments

logical_expression

A valid logical expression. See LET for a description of logical expressions.

Operators

See Bit-Wise Operators for information on the bit-wise operators supported by WHILE.

Description

The WHILE loop continues until the condition being tested is FALSE.

An expression returning 0 (zero) is considered FALSE; an expression returning nonzero is TRUE.

BREAK causes an immediate exit of the WHILE loop; Production Reporting continues with the command immediately following END-WHILE.

CONTINUE ends the current iteration of a loop. Program control passes from the CONTINUE parameter to the end of the WHILE loop body.

WHILE commands can be nested to any level and can include or be included within IF and EVALUATE commands.

Examples

The following example shows an IF nested within a WHILE:

while #count < 50
  do get_statistics
  if #stat_count = 100
    break     ! Exit WHILE loop.
  end-if
  add 1 to #count
end-while

You can use single numeric variables in your expression to make your program more readable, for example when using flags.

move 1 to #have_data
...
while #have_data
   ...processing...
end-while

The following example sets up an infinite loop:

while 1
  ...processing...
  if ...
    break     ! Exit loop
  end-if
end-while

You can use any complex expression in WHILE as shown in the following example:

while #count < 100 and (not #end-file or isnull(&state))
  ...
end-while

The following example shows the use of CONTINUE in a WHILE loop:

while #count < 50
  if #count = 10
    continue
  end-if
  do get-statistics(#count)
  add 1 to #count
end-while

See Also

LET for a description of expressions