Loops

Legacy page. This page predates the v0.2 redesign and may show syntax the v0.1.11 interpreter does not accept. It will be rewritten in P7 Docs truth.

PooLang provides two primary ways to repeat logic: while loops and for loops.

While Loops

The while loop continues to execute as long as its condition remains true.

poo mut count << 0;

while count < 5 {
    pout("Count: ", count);
    count << count + 1;
}

For Loops

PooLang supports for loops that iterate over a range or a collection.

Range Iteration

You can iterate over a range of numbers using the .. syntax:

for i in 0..5 {
    pout(i); # Prints 0, 1, 2, 3, 4
}

Vector Iteration

You can also iterate over elements in a vector:

poo items << [10, 20, 30];

for item in items {
    pout(item);
}

Scoping

The loop variable (like i or item) is only accessible within the body of the loop.