Skip to main content

Loops

Loops in TinyPanda allow you to execute blocks of code repeatedly.

loop (While Loop)

The loop statement acts as a traditional while loop. It repeats its block statements as long as its condition expression evaluates to true.

Syntax

loop (condition) {
// statements to execute
}
NOTE

The body of a loop must always be enclosed in curly braces { }, even if it only contains a single statement.

Usage

To run a loop, initialize a control variable, set a termination boundary in the condition, and update the variable inside the loop body.

bamboo x = 1;

loop (x <= 3) {
echoln("The value of x is " + str(x));
x++;
}

// Output:
// The value of x is 1
// The value of x is 2
// The value of x is 3