Top
Back: quit
Forward: while
FastBack: Functions
FastForward: System variables
Up: Control structures
Top: Singular Manual
Contents: Table of Contents
Index: Index
About: About this document

5.2.14 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: quit Forward: while FastBack: Functions FastForward: System variables Up: Control structures Top: Singular Manual Contents: Table of Contents Index: Index About: About this document
            User manual for Singular version 4.3.2, 2023, generated by texi2html.