InstallShield 2018
Like InstallScript’s built-in functions, user-defined functions can be designed to return a value to the caller. To return a value from a function, you must include a return statement, followed by the value to be returned, before the function’s end statement. If you do not include a return statement or if you do not specify a value after the keyword return, the value returned by the function is unpredictable. (If the function prototype specifies a return type of void, the function cannot return a value.)
Many programmers use return statements to return error codes that indicate the success or failure of a function call. Most of InstallScript’s built-in functions use a return statement for that purpose. The return statement also is used commonly to create functions that return the result of an operation performed on parameters passed to the function, as in the example below, which returns the area of a rectangle:
function RectangleArea (nLength, nWidth)
INT nVal;
begin
nVal = (nLength * nWidth);
return nVal;
end;
The keyword return can be followed by a constant, a variable, a numeric or string expression, or a function call. In the example below, RectangleArea has been modified to eliminate the assignment statement; the arithmetic expression follows the keyword return:
function RectangleArea (nLength, nWidth)
begin
return (nLength * nWidth);
end;
The value returned by a function can be ignored by the calling program or function, tested in a conditional expression, or assigned to a variable. In the following example, the return value from RectangleArea is assigned to the variable nArea:
nArea = RectangleArea (nLong, nWide);
In the next example, the result of RectangleArea is tested in a conditional expression:
if (RectangleArea(nLong, nWide) > nMaxArea) then
MessageBox("Area exceeds maximum allowed.", INFORMATION);
endif;
To return more than one value or non-numeric values, use the BYREF operator to define parameters that are passed by reference.
See Also
BYREF Operator
Declarations
return
Open topic with navigation
FAQs
To return a value from a function, you must include a return statement, followed by the value to be returned, before the function's end statement. If you do not include a return statement or if you do not specify a value after the keyword return, the value returned by the function is unpredictable.
How do you check if a function returns a value? ›
The most basic way is to use an if statement:
- if function() == value:
- print ("function returned ", value)
- else:
- print ("function did not return ", value)
How many values can a value returning function return? ›
Even though a function can return only one value but that value can be of pointer type.
How would you return a value from a function in Python? ›
The Python return statement is a special statement that you can use inside a function or method to send the function's result back to the caller. A return statement consists of the return keyword followed by an optional return value. The return value of a Python function can be any Python object.
What is a return statement in a function? ›
A return statement ends the execution of a function, and returns control to the calling function. Execution resumes in the calling function at the point immediately following the call. A return statement can return a value to the calling function. For more information, see Return type.
How do you return two values from a function? ›
Using Structures
Structures in C can also return more than one value from a function. In C, a structure is a user-defined datatype that may store multiple data types of the same or different types. The objective is to construct a struct with all essential data types as members and return that struct from our function.
When should a function return a value? ›
Generally, a return value is used where the function is an intermediate step in a calculation of some kind. You want to get to a final result, which involves some values that need to be calculated by a function.
What happens when a function returns? ›
The return statement can only be used within function bodies. When a return statement is used in a function body, the execution of the function is stopped. The return statement has different effects when placed in different functions: In a plain function, the call to that function evaluates to the return value.
What is the IF function to return a value? ›
Use the IF function, one of the logical functions, to return one value if a condition is true and another value if it's false. For example: =IF(A2>B2,"Over Budget","OK") =IF(A2=B2,B4-A4,"")
What is an example of return? ›
Examples of return in a Sentence
Verb We waited for you to return. She is returning home tomorrow. I'm leaving but will return at 2 p.m.
Answer. NO, a function does not always have to have an explicit return statement. If the function doesn't need to provide any results to the calling point, then the return is not needed.
How to return a value from a function? ›
To return a value from a function, you must include a return statement, followed by the value to be returned, before the function's end statement. If you do not include a return statement or if you do not specify a value after the keyword return, the value returned by the function is unpredictable.
How to find the output of a function? ›
If a function is expressed as a graph, the inputs and outputs can be found by looking at the graph. Pick any point on the graph, and find its value along the bottom and left of the graph. The point's value on the bottom of the graph is the input, and the point's value on the left of the graph is the output.
What does values () return in Python? ›
The values() method returns a view object. The view object contains the values of the dictionary, as a list. The view object will reflect any changes done to the dictionary, see example below.
What is the function to return a value in Excel? ›
The INDEX function returns a value or the reference to a value from within a table or range. There are two ways to use the INDEX function: If you want to return the value of a specified cell or array of cells, see Array form.
How do you use the IF function to return a value? ›
Use the IF function, one of the logical functions, to return one value if a condition is true and another value if it's false. For example: =IF(A2>B2,"Over Budget","OK") =IF(A2=B2,B4-A4,"")
How to return values from functions in R? ›
We generally use explicit return() functions to return a value immediately from a function. If it is not the last statement of the function, it will prematurely end the function bringing the control to the place from which it was called.
Can you return a function from a function? ›
Functions are the same data as numbers or strings, so functions can be passed to other functions as arguments, as well as returned from functions. We can even define a function inside another function and return it outside. And this is not surprising.