# RETURN

## Purpose:

Terminates an iteration or a function, and optionally returns a value.

## Syntax:

RETURN(val1, val2, ..., valN)

 valN - Optional. Zero or more strings, scalars, series or tables.

## Example:

IntgVal(s)
{
ival = max(integ(s));

return(ival);
}

The SPL function, IntgVal, returns the max of the integral of the series, s.

## Example:

Consider myfunction defined as follows:

myfunction(x)
{
if (outargc > 1)
{
return(x, x * x);
}
else
{
return(x);
}
}

(a,b) = myfunction(10)

assigns a the value 10 and b the value 100

a = myfunction(10)

only assigns a.

## Example:

AVGHIST is an example of an SPL routine to calculate a histogram where the X values are the average of the points within a bin: Either the histogram as a whole or the separate X and Y components can be returned.

avghist(s, n)
{
local h, a;

if (argc < 2)
{
if (argc < 1) error("avghist - input required");

n = 10;
}

// first get normal histogram
h = hist(s, n);

// sort original data in ascending order
a = sort(s, -1);

// reshape such that each column is actual bin values
a = reshape(a, h, 1, 0, 1);

// compute mean of each bin
a = transpose(colmean(a));

// return components or full XY graph
if (outargc > 1)
{
// (x, y) = avghist(s, n)
return(a, h);
}
else
{
return(xy(a, h));
}
}

## Remarks:

RETURN is for use in SPL files. It can be used with or without optional return values.

Unlike C/C++, the SPL RETURN function can return multiple values.

See OUTARGC to determine the number of requested output return values.

BREAK

FOR

IF

LOOP

OUTARGC

SPL: Series Processing Language

SWITCH

WHILE