previous page next page reference home emBASIC home page

4.6 The RETURN statement
return may only occur syntactically nested in a function, not nested within a procedure definition. If an expression list is present, it is evaluated, else void is substituted. return leaves the current function call with the expression list (or void) as return value.
4.7 The BREAK statement
break may only occur syntactically nested in a for or while loop.
It terminates the nearest enclosing loop.
If a for loop is terminated by break, the loop control target keeps its current value.
4.8 The CONTINUE statement
continue may only occur syntactically nested in a for or while loop. It continues with the next cycle of the nearest enclosing loop.
Example below will output “1 2 ”.
FOR I = 0 TO 2
IF I < 1 THEN CONTINUE
PRINT I; “ “;
NEXT I
5 Compound statements
5.1 Introduction
Compound statements contain (groups of) other statements; they affect or control the execution of those other statements in some way. In general, compound statements span multiple lines, although in simple incarnations a whole compound statement may be contained in one line.
The if, switch, while, repeat, for and loop statements implement traditional control flow constructs. Note that statements always end in the end of line (EOL). Also note that unreferenced END statements cause compilation errors.
5.2 The IF statement
The if statement is used for conditional execution:
IF expression [THEN] statement(s)
( ELSEIF expression [THEN] statement(s) )*
[ELSE statement(s)]
END
It selects exactly one of the statement(s)s by evaluating the expressions one by one until one is found to be true ; then that statement(s) is executed (and no other part of the if construct is executed or evaluated). If all expressions are false, the statement(s) of the else clause, if present, is executed.
Statement(s) is comprised of one or more statements spread over several lines or separated by a semicolon.
Note that the THEN clause is optional when a multiple line block is defined.
Examples:
IF button != pressed
lamp = 1
END

IF a == b
c = 1
ELSEIF a < b
c = 2
ELSEIF a > b
c = 3
ELSE
c = 0
END

5.3 The WHILE statement
The while statement is used for repeated execution as long as an expression is true:
WHILE expression
statement(s)
END
This repeatedly tests the expression before executing any statements. If the expression is true, it executes the statement(s); if the expression is false (which may be the first time it is tested) the loop terminates.
A BREAK statement executed in the statement(s) terminates the loop. A CONTINUE statement executed in the statement(s) skips the rest of the statement(s) and goes back to testing the expression.
5.4 The FOR statement
The for statement is used to iterate over the iterable object:
FOR target = start-expression TO end-expression [STEP increment-expression]
statement(s)
NEXT target
First, the expression is evaluated and assigned to target. Then this repeatedly tests the target to match the end-expression and if it is true the loop terminates. The optional STEP clause performs and arithmetic addition to target when the NEXT statement is reached.
5.5 The SWITCH statement
This evaluates the expression and performs matching with the case patterns, then executes matching statement(s) of statement(s) under DEFAULT clause if any:
SWITCH '(' expression ')'
CASE ['<' | '>'] number | char
statements
CASE number [ ',' number . . .] |
statements
CASE number .. number |
DEFAULT
statements
END
5.6 The LOOP statement
The loop statement is used for infinitely repeated execution:
LOOP
statement(s)
END
This repeatedly executes the statement(s). A BREAK statement executed in the statement(s) terminates the loop. A CONTINUE statement executed in the statement(s) skips the rest of the statement(s) and goes back to the start.
5.7 The REPEAT statement
This repeatedly tests the expression after at least once execution of statement(s) and, if it is true, goes back to the start; if the expression is false the loop terminates.
REPEAT
statement(s)
UNTIL expression

Referenzauf WAIT statement ###