The return Statement exits from the current function and returns a value from that function.
Syntax:
Return [() [expression] [];
The optional expression parameter is the value to be returned from the function. If omitted, the function does not return a value.
Use the return statement to terminate the execution of a function and return the value of expression. If expression is omitted or no return statement is executed in the function, the undefined value is assigned to the expression that calls the current function.
The following example illustrates the usage of the return Statement:
Function myfunction (arg1, arg2) {var r; r = arg1 * arg2; return (r );}
Return: return from the called function to the main function for execution. A return value can be included in the return, which is specified by the parameters following return. Return is usually necessary, because the computation results are usually obtained through the return value during function calls.
If you do not need the function to return any value, you need to use void to declare its type.
Supplement: If you have a return type definition before the function name, such as int or double, you must have a return value. If it is void, you can leave the return value blank, however, even if the data is written, the following values cannot be returned:
The following is a non-void function:
Int f1 () {int I = 1; return 1; // return (I); // This can also be done}
Void functions:
Void f2 () {int I = 1; // return; // This can also be done. Do not use this sentence}