Spice3f5

Control structures

While - End

General form

while condition
        statement
        ...
end

While condition, an arbitrary algebraic expression, is true, execute the statements.

Repeat - End

General form

repeat [number]
        statement
        ...
end

Execute the statements number times, or forever if no argument is given.

Dowhile - End

General form

dowhile condition
        statement
        ...
end

The same as while, except that the condition is tested after the statements are executed.

Foreach - End

General form

foreach var value ...
        statement
        ...
end

The statements are executed once for each of the values, each time with the variable var set to the current one. (var can be accessed by the $var notation - see below).

If - Then - Else

General form

if condition
        statement
        ...
else
        statement
        ...
end

If the condition is non-zero then the first set of statements are executed, otherwise the second set. The else and the second set of statements may be omitted.

Label

General form

label word

If a statement of the form goto word is encountered, control is transferred to this point, otherwise this is a no-op.

Goto

General form

goto word

If a statement of the form label word is present in the block or an enclosing block, control is transferred there. Note that if the label is at the top level, it must be before the goto statement (i.e, a forward goto may occur only within a block).

Continue

continue

If there is a while, dowhile, or foreach block enclosing this statement, control passes to the test, or in the case of foreach, the next value is taken. Otherwise an error results.

Break

General form

break

If there is a while, dowhile, or foreach block enclosing this statement, control passes out of the block. Otherwise an error results.

Of course, control structures may be nested. When a block is entered and the input is the terminal, the prompt becomes a number of >'s corresponding to the number of blocks the user has entered. The current control structures may be examined with the debugging command cdump.