Programmer Guide/Command Reference/DO: Difference between revisions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
{{DISPLAYTITLE:{{SUBPAGENAME}}}} | {{DISPLAYTITLE:{{SUBPAGENAME}}}} | ||
The two flavours of the <code>DO</code> command are <code>[[Programmer Guide/Command Reference/WHILE|DO WHILE]]</code> (or, simply, <code>WHILE</code>, and <code>[[Programmer Guide/Command Reference/FOREVER|DO FOREVER]]</code> (or, simply, <code>FOREVER</code>). | The two flavours of the <code>DO</code> command are <code>[[Programmer Guide/Command Reference/WHILE|DO WHILE]]</code> (or, simply, <code>WHILE</code>), and <code>[[Programmer Guide/Command Reference/FOREVER|DO FOREVER]]</code> (or, simply, <code>FOREVER</code>). | ||
== DO WHILE == | == DO WHILE == | ||
{{:Programmer_Guide/Command_Reference/WHILE}} | {{:Programmer_Guide/Command_Reference/WHILE}} |
Latest revision as of 16:15, 5 April 2011
The two flavours of the DO
command are DO WHILE
(or, simply, WHILE
), and DO FOREVER
(or, simply, FOREVER
).
DO WHILE
WHILE condition … END
or
DO WHILE condition … END
Provided that the conditional expression condition holds true, the commands in the block enclosed by the WHILE
, or DO WHILE
, and the corresponding END
statement are repeatedly executed until condition becomes false.
To put it more bluntly: The condition is always tested on the begin of the loop, that is, before executing the respective block of commands. With STx, there is no explicit loop statement checking its condition at the end of the loop, but if this is what you are longing for, you will find relief by combining the FOREVER statement with an appropriate IF, and BREAK, statement.
Note that it is perfectly legal to prematurely leave a loop with a GOTO
statement, though, generally, GOTO
is considered harmful.
DO FOREVER
The FOREVER
, or DO FOREVER
, statement starts a, potentially infinite, loop. The commands between FOREVER
or DO FOREVER
and the corresponding END
statement are being executed forever, or until execution of the loop gets interrupted by other means, e.g. by STx crashing, a BREAK
statement being encountered, or an EXIT
, or a GOTO statement being executed.
FOREVER
or
DO FOREVER
Cave: If you do not use a BREAK
, EXIT
, or GOTO
command for interrupting the loop, it may run for a really long time.