Returning

Normally a function is one or several expressions separated by a semicolon, and the value of the last expression is returned. This is fine for simple functions, but sometimes you do not want a function to return the last thing calculated. You may, for example, want to return from a middle of a function. In this case, you can use the return keyword. return takes one argument, which is the value to be returned.

Example:

function f(x) = (
  y=1;
  while true do (
    if x>50 then return y;
    y=y+1;
    x=x+1
  )
)