Next: reverse() Up: MacAnova Help File Previous: restore()   Contents

return

Usage:
return(x), x a variable or constant, only in a macro
return and return() are equivalent to return(NULL)



Keywords: control, syntax, macros
Syntax element 'return' is used to leave a macro immediately, skipping
any following expressions or commands.  It may be used only in the text
of a macro.

In a macro, when 'return(Value)' is executed, the macro is immediately
terminated and Value is returned as the macro value.  Value can be any
constant, variable or expression.  'return(Value)' must be followed by
';' or '}' or be at the end of a line.

In a macro, 'return()' and 'return', with no parentheses, are equivalent
to 'return(NULL)'.

'return(Value), 'return()' and 'return' are typically the last command
in the compound command (see topic 'syntax') that follows 'if(...)',
'elseif(...)' or 'else' (see topic 'if'), or as the last command in a
macro.

'return' may not be used in an evaluated string unless it is in a macro
invoked in that evaluated string.  This is true even if the string being
evaluated is within a macro.  See evaluate().

Example:
  Cmd> checkit <- macro("if($1==1){return(\"one\")}
       if($1 == 2){return(\"two\")};return(\"not one or two\")")

  Cmd> reply <- checkit(1); reply
  (1) "one"

  Cmd> reply <- checkit(3); reply
  (1) "not one or two"

The final 'return(...)' could be replaced simply by "not one or two",
since the default return value is the last expression or variable in the
macro.

See also macro(), 'macros', 'macro_syntax', 'break', 'next'


Gary Oehlert 2003-01-15