Home Reference VEX 

Loops and flow control

See also VEX functions. Most of the work in VEX is done with function calls. Most of the statements are looping constructs, many of which may be familiar from other languages such as C. While print is a statement in some languages (such as Python), in VEX you print using the printf function.

{}

As in C and many other languages, you can enclose multiple statements inside curly braces to act as a block.

For example, the if statement can execute one statement:

if ( needs_zapping() ) zap()

…or a block inside curly braces:

if ( needs_zapping() ) {
zap()
disintegrate()
remove_dust()
}

do loop

do statement [while (condition)]

Executes statement, and then loops if condition is true. Unlike while, do is guaranteed to execute the statement at least once.

for loop

for (init; condition; change) statement

Standard C-style for loop. Performs the init statement, then executes statement repeatedly while condition is true, executing the change statement at the end of each iteration.

if

if (condition) statement_if_true [else statement_if_false]

Executes statement_if_true if condition is true.

If the else clause is included, statement_if_false is executed if condition is false.

return

Exits the function with an optional return value.

int max(int a, b) {
if (a > b) {
return a;
}
return b;
}

while loop

while (condition) statement

Executes statement repeatedly while condition is true.

Other looping statements

The forpoints, illuminance, and gather statements let you loop over data being processed by VEX.