Countdown

A while loop with decr! and an else: peer that runs when the counter reaches zero – used in the from-python Data and control chapter.

The program

def countdown [n]:
  while (> n 0):
    print n
    decr! n
  else:
    print "lift-off"

@entry-point
def main []:
  (countdown 3)

Run

Save as countdown.ki and:

koskari countdown.ki

Expected:

3
2
1
lift-off

See also