In
C and
C++, return
exp; (where
exp is an
expression) is a
statement that tells a function to return execution of the program to the calling function, and report the value of
exp. If a function has the return type
void, the return statement can be used without a value, in which case the program just breaks out of the current function and returns to the calling one. and
Python. In
Pascal there is no return statement. Functions or procedures automatically return when reaching their last statement. The return value from a function is provided within the function by making an assignment to an identifier with the same name as the function. However, some versions of Pascal provide a special function Exit(
exp); that can be used to return a value immediately from a function, or, without parameters, to return immediately from a procedure. Like Pascal,
FORTRAN II,
Fortran 66,
Fortran 77, and later versions of
Fortran specify return values by an assignment to the function name, but also have a return statement; that statement does not specify a return value and, for a function, causes the value assigned to the function name to be returned. In some other languages a user defined
output parameter is used instead of the function identifier.
Oberon (
Oberon-07) has a return clause instead of a return statement. The return clause is placed after the last statement of the procedure body. Some
expression-oriented programming language, such as
Lisp,
Perl and
Ruby, allow the programmer to omit an explicit return statement, specifying instead that the last evaluated expression is the return value of the subroutine. In other cases a Null value is returned if there is no explicit return statement: in
Python, the value None is returned when the return statement is omitted, while in JavaScript the value undefined is returned. In
Windows PowerShell all evaluated expressions which are not captured (e.g., assigned to a variable,
cast to
void or
piped to
$null) are returned from the subroutine as elements in an array, or as a single object in the case that only one object has not been captured. In Perl, a return value or values of a subroutine can depend on the context in which it was called. The most fundamental distinction is a
scalar context where the calling code expects one value, a
list context where the calling code expects a list of values and a
void context where the calling code doesn't expect any return value at all. A subroutine can check the context using the wantarray function. A special syntax of return without arguments is used to return an undefined value in scalar context and an empty list in list context. The scalar context can be further divided into
Boolean, number,
string, and various
reference types contexts. Also, a context-sensitive
object can be returned using a contextual return sequence, with
lazy evaluation of scalar values. Many
operating systems let a program return a result (separate from normal
output) when its process terminates; these values are referred to
exit statuses. The amount of information that can be passed this way is quite limited, in practice often restricted to signalling success or fail. From within the program this return is typically achieved by calling
Exit (system call) (common even in C, where the alternative mechanism of returning from the
main function is available). ==Syntax==