WHILE expression .... ENDWHILE
Purpose

To execute a series of statements in a loop as long as a given condition is true.

Syntax

WHILE expression
. . .
. . .
ENDWHILE

When WHILE statement is encountered, the expression will be evaluated and if the result is true, the statements following the expression will be executed until the ENDWHILE statement. Thereafter, execution branches back to the WHILE statement and the expression is evaluated again. The loop statements will be executed repeatedly until the expression becomes false.

Warning: Be careful that the WHILE loop will not be an endless loop as the PLC will appear to freeze up, being trapped in an endless-loop execution. i-TRiLOGI simulator attempts to detect this situation by giving a warning message if a loop is executed for an unduly large number of loops.
It is possible to break out of a WHILE loop using the GOTO command or the EXIT command (only on PLCs with r75 or higher firmware).

Examples WHILE S = 1
   IF INPUT[1] & &H0002: S = 0 : ENDWHILE
ENDWHILE
Comments: Execution will only be terminated when input #2 is ON. WHILE loops may be nested; i.e. a WHILE loop may be placed within the context of another WHILE loop. Each Loop must have a separate ENDWHILE statement to mark the end of the loop.
See Also FOR ... NEXT

backbutton.gif (507 bytes)  Basic to TBASIC Reference Manual