ExpandCollapseNext Index

+ 1.1 Procedural control

+ 1.1.1 Conditional

Basic conditional is like this:

  proc f(x:int) 
  {
    if x < 0 do
      println$ "Negative";
    elif x == 0 do
      println$ "Zero";
    else
      println$ "Positive";
    done
  }

The elif and else clauses are optional.

+ 1.1.2 While loop

And here's a standard while loop:

  proc f(x:int) 
  {
    while x > 0 do
      println$ x;
      x = x - 1;
    done
  }  

+ 1.1.3 For loop

Felix for loop uses an inclusive range:

  proc f (n:int)
  {
    for var i in 0 upto n - 1 do
      println$ i;
    done
    println$ i;
  }

Note the control variable is available outside the loop. You must leave out the var if the variable is defined elsewhere in the same scope.

+ 1.1.4 Return

Return from a procedure. A procedure returns automatically if control drops through the end.

  proc f(n:int)
  {
    if n < 0 return;
    if n == 0 do
      println$ "Zero";
      return;
    done
    println$ "Positive";
    return;
  }
  

+ 1.1.4.1 Goto

If you really need to:

  proc f(n:int)
  {
    if n < 0 goto endoff;
    println$ "Positive or Zero";
  endoff:>
    println$ "Square is " + (n * n).str;
  }