Do...Loop Statement
Repeats a block of statements while a condition is True or until a condition becomes True.
Syntax
Do [ { While | Until } condition ]
[statements]
[Exit Do]
[statements]
Loop
Or, you can use this syntax:
Do
[statements]
[Exit Do]
[statements]
Loop [ { While | Until } condition ]
The Do Loop statement syntax has these parts:
- Condition
- Optional. Numeric expression or string expression that is True or False. If condition is Null, condition is treated as False.
- statements
- One or more statements that are repeated while, or until, condition is True.
Description
Any number of Exit Do statements may be placed anywhere in the Do...Loop as an alternate way to exit a Do...Loop. Exit Do is often used after evaluating some condition, for example, If...Then, in which case the Exit Do statement transfers control to the statement immediately following the Loop.
When used within nested Do...Loop statements, Exit Do transfers control to the loop that is one nested level above the loop where Exit Do occurs.
Note
DO NOT use XQT command repeatedly in Loop statements.
Do not use XQT command repeatedly in Loop statements such as Do…Loop. The controller may freeze up. If you use Loop statements repeatedly, make sure to add Wait command (Wait 0.1).
Avoid endless execution of empty Loop Statements and similar to them, use them with the Wait command instead
Do not use empty Do…Loop statements and similar commands to avoid effect on the system. The Controllers are detecting endless loop tasks. If the controller determines that the system will be affected, it will stop the program with error 2556 (An excessive loop was detected). When performing operations that require a loop or waiting for I/O, execute a Wait command (Wait 0.1) and more within the loop to avoid occupying the CPU.
When you exit the loop from the nested structure without using Exit Do
Error 2020 will occur when you repeatedly execute the program which exits the loop by the command other than the Exit For command (such as GoSub statement, Goto statement, and Call statement.) Be sure to use Exit Do command to exit the loop.
See Also
For...Next, Select...Send
Do...Loop Statement Example
Do While Not Lof(1)
Line Input #1, tLine$
Print tLine$
Loop