Top
Back: 5.2.9 quit
Forward: 5.2.11 while
FastBack: 5. Functions and system variables
FastForward: 6. Tricks and pitfalls
Up: 5.2 Control structures
Top: Singular 2-0-4 Manual
Contents: Table of Contents
Index: F. Index
About: About This Document

5.2.10 return

Syntax:

return ( expression_list );
return ();

Type:

any

Purpose:

returns the result(s) of a procedure and can only be used inside a procedure. Note that the brackets are required even if no return value is given.

Example:
 
proc p2
{
  int i,j;
  for(i=1;i<=10;i++)
  {
    j=j+i;
  }
  return(j);
}
// can also return an expression list, i.e., more than one value
proc tworeturn ()
{ return (1,2); }
int i,j = tworeturn();
// return type may even depend on the input
proc type_return (int i)
{
  if (i > 0) {return (i);}
  else {return (list(i));}
}
// then we need def type (or list) to collect value
def t1 = type_return(1);
def t2 = type_return(-1);

See Data types; proc.


Top Back: 5.2.9 quit Forward: 5.2.11 while FastBack: 5. Functions and system variables FastForward: 6. Tricks and pitfalls Up: 5.2 Control structures Top: Singular 2-0-4 Manual Contents: Table of Contents Index: F. Index About: About This Document
            User manual for Singular version 2-0-4, October 2002, generated by texi2html.