while Loops
while repeats a block of code as long as a condition is true.
⚠️ Loop Protection
By default, VDX halts a loop when an iteration takes more than 2 seconds of real work or the loop passes 1,000,000 iterations. See Loop Protection and @unsafe.
Syntax
while (condition) {
// body
}Example with wait
Time spent in wait() doesn't count toward the 2-second iteration limit — it only measures real work:
class App {
let i = 5;
while (i > 0) {
print("countdown:", i);
i = i - 1;
wait(2100);
}
print("done!");
}Fast loops with @unsafe
If you need a fast loop, use @unsafe:
class App {
let i = 0;
@unsafe while (i < 100) {
print(i);
i = i + 1;
}
}Loop with function
class App {
fn countdown(n) {
@unsafe while (n > 0) {
print(n);
n = n - 1;
}
}
countdown(5);
}Scoping
Variables declared inside a while block are local to that iteration. See Scoping Rules.