WHILE

WHILE

Top  Previous  Next

 

The WHILE statement is used in conjunction with the FOR / NEXT or LOOP / REPEAT constructs to determine whether execution of the loop should continue.

 

 

Format

 

WHILE expr

 

where

 

exprevaluates to a numeric value

 

 

The WHILE statement causes execution of the innermost FOR/NEXT or LOOP/REPEAT construct to terminate if the value of expr is zero. It is equivalent to a statement such as

 

IF expr = 0 THEN EXIT

 

If the CONDITIONAL.STATEMENTS option of the $MODE compiler directive is active, expr may be one of the following statements that in its normal form has a THEN/ELSE clause:

FILELOCK, FILEUNLOCK, FIND, FINDSTR, FLUSH, GETLIST, LOCATE, MATREAD, MATREADCSV, MATREADL, MATREADU, OPEN, OPENPATH, OPENSEQ, OSREAD, READ, READBLK, READCSV, READL, READLIST, READNEXT, READSEQ, READU, READV, READVL, READVU, SEEK, WRITEBLK, WRITECSV, WRITESEQ

 

When used in this way, the LOCKED or ON ERROR clauses normally associated with some of these statements are not available.

 

 

Examples

 

LOOP

  REMOVE ITEM FROM LIST SETTING DELIMITER

  DISPLAY ITEM

WHILE DELIMITER

REPEAT

 

This program fragment displays items removed from dynamic array LIST. The loop is terminated when the value of DELIMITER becomes zero.

 

 

SELECT FV

LOOP

WHILE READNEXT ID

  ...processsing...

REPEAT

 

The above program fragment, which requires the CONDITIONAL.STATEMENTS option of the $MODE compiler directive to be active, uses the READNEXT statement as a conditional element in the loop.

 

 

See also:

EXIT, UNTIL