|
<< Click to Display Table of Contents >> RETURN |
![]() ![]()
|
The RETURN statement returns from a program file or procedure/function (i.e., does not execute subsequent statements). It will return to any 'parent' program file/procedure/function calling that particular 'child' program file/procedure/function. If you need to return from the whole 'call stack' of program files/procedures/functions at once, you may alternatively use the STOP statement. (To stop/abort a program while it is running, you may use the red stop button in the user interface).
return ;
If RETURN is used to return from a FUNCTION (that is, if the function returns one or more variables), the following syntax is used:
return expression ; //return from function
To see how RETURN works regarding program files, try creating the two program files file1.gcm and file2.gcm as shown below. Then call the first one of these from the statement prompt with run file1;. Next, if you issue a prt %i;, the value will be 1101, because the third line file2.gcm is never executed. With a STOP instead of RETURN in file2.gcm, the value of %i would be 1001, because the third line of file1.gcm (the 'parent' program file) would not have been have been executed.
------------- file1.gcm -------------- |
•The similar STOP statement returns from all program files/procedures/functions at once.
•The EXIT statement effectively issues a STOP, and then afterwards closes the Gekko application.
•In function definitions where a variable is returned, at least one RETURN statement is mandatory.
If you wish to comment out a section of the program file, you may use // to comment out a single line, or /* followed by */ to comment out an arbitrary section (for instance spanning multiple lines).