Loops
Repeatedly execute a section of code in RapidScript.
Every type of loop contains these components:
A condition expression: This expression is evaluated before every iteration. It must evaluate to a
bool
value. If it evaluates totrue
, the code block is executed and the loop continues to iterate. If it evaluates tofalse
, the code block is not executed and the loop terminates.A block of code to execute every iteration.
Each type of loop adds some additional components.
For
For loops add the following components:
The
for
keyword.An initialization expression: This expression is executed before the first iteration of the for loop. It is typically used to set up and initialize necessary variables.
An iteration expression: This expression is executed after every iteration. It is typically used to increment an iteration variable.
While
While loops add the following components:
The
while
keyword.
Do While
Do While loops differ slightly from the other loops. Its code block is guaranteed to execute at least once, regardless of whether or not the condition evaluated to true
. Subsequent iterations check the condition before executing and will terminate if it evaluates to false
. Do While loops add the following components:
The
do
keyword.The
while
keyword.
Special Statements
break;
Skip the remainder of the current iteration of a loop and terminate the enclosing loop.continue;
Skip the remainder of the current iteration of a loop (but continue looping).
Last updated