Control Structures
Zoomscript current supports 4 control structures:
- Repeat loop: a loop structure that repeats the code block a specified number of times.
- While loop: a loop structure that repeats the code block while a given boolean expression is true. The loop ends when the expression is false.
- If statement: the code block is executed if and only if a given boolean expression is true. If false, the code is ignored.
- If-else statement: same as an if statement, but if the expression is false, a different code block is executed.
Nested loops are currently not supported.
Repeat loop
Repeat loops are identified by the following format:
repeat [integer]
[Code block]
endrepeat
Repeat loops require an integer value. If the value is 0 or less, the loop will still run once.
Repeat loops also support variable values. If the value isn't an integer, the loop will still run once.
While loop
While loops are identified by the following format:
while [expression]
[Code block]
endwhile
While loops require a boolean expression. The expression must be true or false. If the expression is not a boolean, your program will crash with a ControlError.
While loop expressions support variables and function calls as parameters. Functions must return a boolean value.
If statement
If statements are identified by the following format:
if [expression]
[Code block]
endif
If statements require a boolean expression. The expression must be true or false. If the expression is not a boolean, your program will crash with a ControlError.
Similar to while loop expressions, variables and function calls are supported as parameters.
If else statements
The same as if statements, but with a secondary 'else' code block:
if [expression]
[Code block]
else
[Code block]
endif
Continuous if-else statements are not supported. Use nested if-statements instead.