loop()

The loop statement provides a compact way to execute function multiple times.

If the function executed returns `NaN`, the loop terminates.

Hint: Use exec function to execute block.

Syntax

loop(count, function)

Parameters

Parameter Type Description
count Number The number of times to execute the statement.
function Any The function to execute in each iteration. If it returns `NaN`, the loop stops.

Return Value

Examples

Print “Current num is X/Y” five times

loop(5, print("Current num is ", .arg1, "/", .arg2));

Output:
Current num is 0/5
Current num is 1/5
Current num is 2/5
Current num is 3/5
Current num is 4/5

See also

for
loop
exec