On this page |
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.
foreach loop ¶
foreach (‹value›; ‹array›) ‹statement›
foreach (‹index›, ‹value›; ‹array›) ‹statement›
Executes ‹statement› for each member of ‹array› (optionally sets ‹index› to the current position in the array). See foreach.
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.
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; }
break ¶
break
immediately exits the loop. It is useful with the if
statement to stop looping early when some condition is reached.
for (int i = 0; i < sizes; i++) { mixamount += getAmount(roughness); if (mixamount > 1) { break; } }
continue ¶
continue
jumps immediately to the next iteration of the loop.
foreach (x; myarray) { if (x < 10) continue; ... }