API Reference › Control flow › break
keyword

break

break

break exits the innermost while or for loop at once, skipping the rest of the body and any remaining iterations, and continues with the code after the loop. Use it to stop early the moment you have what you need — the first match in a scan, a collision that ends the sweep, or a guard inside while true that decides when to leave. It affects only the loop that contains it; an outer loop keeps running.

Example

program FindFirst {
  var found: int = 0 - 1

  handler Scan phase Update {
    for i in 0 .. 10 {
      if i * i > 20 {
        found = i
        break        # stop at the first i whose square exceeds 20
      }
    }
  }
}
← All symbols