up previous next
Return

exit from a structured command
Syntax

Return
Return E

where E is an expression.


Description
This function is used to exit from a structured command. The latter form returns the value of the expression E to the user. If executed within a nested loop or inside a user-defined function, it breaks out back to the top level, not just to the next higher loop. (For breaks to the next higher loop, see Break .)

Example
  Define Rev(L) -- reverse a list
    If Len(L) < 2 Then Return L EndIf;
    M := Rev(Tail(L)); -- recursive function call
    H := Head(L);
    Return Concat(M,[H]);
  EndDefine;
  Rev([1,2,3,4];
[4, 3, 2, 1]
-------------------------------
  -- Another example: returning from a nested loop
  For I := 1 To 5 Do
    For J := 1 To 5 Do
      If J > 2 Then Return Else Print [I, J], " "; EndIf
    EndFor;
  EndFor;
[1, 1] [1, 2]
-------------------------------


See Also