Skip to content

It creates a conditional loop:

var i = 0
while i < 10:
  echo i
  i += 1

You can create an infinite loop like:

while true:
  echo "."

break

Immediately leaves the loop body.

var i = 0
while true:
  if i > 5:
    break

echo i

If you are using nested loops, you can use labeled blocks to indicate to which block it will break:

# This code will print "outer"
block outer:
  while true:
    block inner:
        while true:
            break inner
            #break outer
    echo "inner"
    break outer

echo "outer"

continue

continue skips the rest of the loop body for a new iteration.

var i = 0
while true:
  if i > 3 and i <= 5:
    i += 1      # required to avoid infinite loop
    continue
  elif i > 5:
    break
  echo "inner ", i
  i += 1
  # `continue` will take you here

echo "end"