Exit

exit breaks out of scopes until a loop or function call is reached.

Concepts Used

Overview

Usually the commands of a scope are executed until the end is reached. The exit statement can stop execution of the scope it is in.

loop (
  input is 'q then exit
)

Note: This is one of the more complex features of the language.

Examples

Stopping when the user pressed a key:

loop (
  key is ('ctrl 'q) exit
)
number-name(number): (
  number is 1 then ('one exit)
  number is 2 then ('two exit)
  number is 3 then ('three exit)
)

number-name 1 should-be 'one
number-name 2 should-be 'two
range(from to body!): (
    from = current
    while (current < to) (
        current + 1 = current
        current body!
    )
)

range 1 10 (
  is 3 then exit
)
exit-on-3: (
  # Return a truthy value when the loop should exit.
  is 3
)

1 to 10 each (
  # Use the return value to determine if the loop should be stopped.
  exit-on-3 then exit
)

Exit not breaking out of a scope

((exit) 1)

Further Reading