Difference between revisions of "Programmer Guide/Command Reference/WHILE"

From STX Wiki
Jump to navigation Jump to search
Line 11: Line 11:
 
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 [[Programmer_Guide/Command_Reference/FOREVER|FOREVER]] statement with an appropriate [[Programmer_Guide/Command_Reference/IF|IF]], and [[Programmer_Guide/Command_Reference/BREAK|BREAK]], statement.
 
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 [[Programmer_Guide/Command_Reference/FOREVER|FOREVER]] statement with an appropriate [[Programmer_Guide/Command_Reference/IF|IF]], and [[Programmer_Guide/Command_Reference/BREAK|BREAK]], statement.
  
Note that it is perfectly legal to prematurely leave a loop with a <code>[[Programmer_Guide/Command_Reference/BREAK|GOTO]]</code> statement, though, generally, <code>GOTO</code> is considered harmful.
+
Note that it is perfectly legal to prematurely leave a loop with a <code>[[Programmer_Guide/Command_Reference/BREAK|GOTO]]</code> statement, though, generally, <code>[[Programmer_Guide/Command_Reference/BREAK|GOTO]]</code> is considered [http://en.wikipedia.org/wiki/Harm harm]ful.

Revision as of 16:51, 7 May 2014

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.