Function arguments

Most function declarations include one or more function arguments. Function arguments are declared after the name of the function between parentheses.

Examples:

complex func square(const complex x)
; Squares x and returns the result.
  return x * x
endfunc

func square2(complex &x)
; Squares x and returns the result in x.
  x = x * x
endfunc

bool func isPowerOfTwo(int value, int &powerOfTwo)
; Checks if value is a power of 2, such as 32 or 64. If so, returns true
; and returns the power of two in powerOfTwo. Otherwise returns false.
  powerOfTwo = 0
  if value > 0
    int mask = 1
    int i = 0
    while i < 31
      if value == mask
        powerOfTwo = i
        return true
      endif
      mask = mask * 2
      i = i + 1
    endwhile
  endif
  return false
endfunc

; Examples of how to call these functions:
complex c = (2, 0)
c = square(c)  ; c = (4, 0)
square2(c)     ; c = (16, 0)
int pow
if isPowerOfTwo(64, pow)
  ; pow = 6 here, because 2^6 = 64.
  ...
endif

Next: Classes

See Also
Built-in functions
Methods