Programmer Guide/Command Reference/IF: Difference between revisions

From STX Wiki
Jump to navigationJump to search
m (1 revision: Initial import)
No edit summary
 
(13 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
==IF==
There are two forms of the <code>IF</code> syntax. The first allows the conditional execution of one command:


There are two forms of the <code>IF</code> syntax. The first allows the conditional execution of one command. The second allows conditional execution of multiple command within a block.
IF [[Programmer_Guide/Concepts/Conditional_Expressions|<var>condition</var>]] singlecommand


<code>IF <var>condition command</var></code>
IFNOT [[Programmer_Guide/Concepts/Conditional_Expressions|<var>condition</var>]] singlecommand


<code>IFNOT <var>condition command</var></code>
The second allows conditional execution of multiple commands within a block:


Conditional execution of a command. For more information on conditions see [[Programmer Guide/Command Reference/condition|condition]].
IF <var>[[Programmer_Guide/Concepts/Conditional_Expressions|condition<sub>1</sub>]]</var> THEN
    &hellip;
ELSE IF <var>[[Programmer_Guide/Concepts/Conditional_Expressions|condition<sub>2</sub>]]</var> THEN
    &hellip;
ELSE IFNOT <var>[[Programmer_Guide/Concepts/Conditional_Expressions|condition<sub>n</sub>]]</var> THEN
    &hellip;
ELSE
    &hellip;
END


<code>IF condition THEN</code>
Note that only the <code>IF</code> 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 <code>[[Programmer Guide/Command Reference/END|END]]</code> statement. For more information on conditions see [[Programmer_Guide/Concepts/Conditional_Expressions|Conditional Expressions]].


<code>...</code>
Neither the [[Programmer_Guide/Concepts/Conditional_Expressions|<var>condition</var>]] nor the <code>singlecommand</code> should contain the string <code>THEN</code>. If either does, in most cases {{STx}} will amazingly mistake the whole command for an ill-formed <code>IF</code> &hellip; <code>THEN</code> &hellip; <code>END</code> block.
 
<code>ELSE IF condition THEN</code>
 
<code>...</code>
 
<code>ELSE IFNOT condition THEN</code>
 
<code>...</code>
 
<code>ELSE</code>
 
<code>...</code>
 
<code>END</code>
 
Conditional execution of command blocks. Only the <code>IF</code> clause is necessary, all others are optional. Both command forms <code>IF</code> and <code>IFNOT</code> can be used. Empty clauses (without commands) are allowed. The last clause must be closed with <code>[[Programmer Guide/Command Reference/END|END]]</code>. For more information on conditions see [[Programmer Guide/Command Reference/condition|condition]].

Latest revision as of 16:42, 25 April 2014

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 IFTHENEND block.

Navigation menu

Personal tools