Loop Protection

VDX includes built-in loop safety. By default, every while, for, and for-in loop is monitored at runtime. If a single iteration takes more than 2000 milliseconds (2 seconds), the loop is immediately halted with an error.

Why?

Infinite loops (or extremely fast loops) can freeze your program, consume all CPU, and make debugging painful. VDX prevents this by default so you can write safer code without thinking about it.

How it works

Each time a loop body finishes one iteration, VDX checks how long that iteration took. If it took more than 2 seconds, the runtime throws an error:

[VDX] Loop safety: iteration took 2500ms (> 2000ms maximum).
      This loop may be infinite or too slow.
      Use @unsafe before the loop to disable this protection:
      @unsafe while (condition) { ... }

Example: blocked loop

class App {
    let i = 0;
    // This will be BLOCKED — each iteration takes > 2s
    while (i < 100) {
        print(i);
        i = i + 1;
        wait(2100);
    }
}

Example: safe loop with wait

class App {
    let i = 0;
    // This is fine — each iteration completes in < 2s
    while (i < 5) {
        print(i);
        i = i + 1;
    }
}

Bypassing with @unsafe

If you know what you are doing and need a fast loop, use the @unsafe annotation. See the @unsafe documentation for details.