Programmer Guide/Command Reference/END: Difference between revisions
m (1 revision: Initial import) |
No edit summary |
||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
{{DISPLAYTITLE:{{SUBPAGENAME}}}} | {{DISPLAYTITLE:{{SUBPAGENAME}}}} | ||
The <code>END</code> statement closes a block of commands started with a [[Programmer_Guide/Command_Reference/IF|block <code>IF</code>]] or with a loop command ([[Programmer_Guide/Command_Reference/FOR|FOR]], [[Programmer_Guide/Command_Reference/DO|DO]], [[Programmer_Guide/Command_Reference/WHILE|WHILE]], [[Programmer_Guide/Command_Reference/FOREVER|FOREVER]]). | |||
<code> | == The <code>IF</code> statement == | ||
{{:Programmer_Guide/Command_Reference/IF}} | |||
== The <code>WHILE</code>, or <code>DO WHILE</code> command == | |||
{{:Programmer_Guide/Command_Reference/WHILE}} | |||
== The <code>FOREVER</code>, or <code>DO FOREVER</code> command == | |||
{{:Programmer_Guide/Command_Reference/FOREVER}} |
Latest revision as of 19:17, 23 March 2011
The END
statement closes a block of commands started with a block IF
or with a loop command (FOR, DO, WHILE, FOREVER).
The IF
statement
There are two forms of the IF
syntax. The first allows the conditional execution of one command:
IF condition singlecommand
IFNOT condition singlecommand
The second allows conditional execution of multiple commands within a block:
IF condition1 THEN … ELSE IF condition2 THEN … ELSE IFNOT conditionn THEN … ELSE … END
Note that only the IF
clause is mandatory, all other clauses are optional. Empty clauses (i.e., clauses without commands) are allowed. The last clause must be closed with an END
statement. For more information on conditions see Conditional Expressions.
Neither the condition nor the singlecommand
should contain the string THEN
. If either does, in most cases STx will amazingly mistake the whole command for an ill-formed IF
… THEN
… END
block.
The WHILE
, or DO WHILE
command
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.
The FOREVER
, or DO FOREVER
command
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.