Skip to content

15 Conditional loops ​

A condition-style for repeats while its Boolean condition remains true.

norm
main() {
  Integer remaining = 3
  Integer total = 0
  for remaining > 0 {
    printLine(remaining)
    total = total + remaining
    remaining = remaining - 1
  }
  printLine("done")
  printLine(total)
}

Expected output:

text
3
2
1
done
6

The condition is checked before every iteration, so a false initial condition runs the body zero times. Updating remaining in the body makes this loop terminate.

Try it: Change the initial value to zero and predict the output.

Precise rules: Reference.

Norm 0.25