WHILE
expression .... ENDWHILEPurpose | To execute a series of statements in a loop as long as a given condition is true. |
Syntax | WHILE expressionWhen 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. TRiLOGI simulator attempts to detect this situation by giving a warning message if a loop is executed for an unduly large number of loops. |
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 |
Basic to TBASIC Reference Manual