|
|
Syntax
if (<Test expression>)
Instruction1 is only executed if the test expression is true (returns a value that does not equal zero). Otherwise the instruction is skipped and execution continues with instruction2 in the optional else section. If there is no else section, the command that follows instruction1 is executed if the test expression is false. |
Example
main() |
|
Syntax
switch(<Test
expression>)
The commands that are executed are all those contained in that case section whose relational expression has the same value as the test expression. If none of the relational expressions in the switch construct meet this condition, then only the instruction in the optional "default" section is executed. If there is no default part, execution continues with the instruction following the switch construct. In order to prevent executing all the other instructions in the switch construct after performing an instruction in a case section, a break statement must be used to escape it. |
Caution |
Note that only expressions whose value is known
at the parse time (constant expressions) are allowed. Such expressions
are: NOT ALLOWED are expressions whose value can be determined
first at runtime. Such expressions are: |
Example
|
|
Syntax
while (<Test
expression>)
InstructionW is only executed if the test expression is true (returns a value that does not equal zero). As soon as the instruction has been executed the test expression is evaluated again. If it is still true, instructionW is executed again. If the test expression is false, instructionW is skipped, and execution continues with the next command. |
Example |
The following script calculates the factorial of 10 (10! = 1*2*3 ...*10).
main() |
|
Syntax
for ([<expression1>];
[<Test expression>]; [<expression3>])
Expression1 is evaluated before the loop is first executed. Normally this is the initialization of a counter variable. InstructionF is only executed if the test expression is true (returns a value that does not equal zero). As soon as the instruction has been executed expression3 and the test expression are evaluated. If the test expression is still true, instructionF is executed again. If the test expression is false, instructionF is skipped, and execution continues with the next command. Each of the three expressions in the condition statement is optional. If there is no test expression then the condition is always considered true. Thus the first of the following examples sets up an endless loop: |
Example of an endless loop
main() |
Example 2
main() |
|
Syntax
do
<instructionD>
while (<Test expression>)
do
As soon as instructionD has been executed the test expression is evaluated again. If it is true (returns a non-zero value) instructionD is executed again. If the test expression is false, execution continues with the next command. |
Example
main() |
|
Syntax
break;
After a break instruction, execution continues with that command that follows the innermost enclosing do, while or for loop, or switch instruction. |
|
Syntax
continue; After a continue instruction, execution continues at the end of the innermost enclosing do, while or for loop. At the same time all expressions in the loop condition are evaluated again. |
V 3.11 SP1
Copyright ETM professional control GmbH 2013 All Rights Reserved