Implementing the Function Content
- Updated2026-04-22
- 2 minute(s) read
To implement the function content, you can create and use local variables. You can use the entire functionality of PAscript to implement function content. Use the return keyword to prematurely terminate evaluation of a function.
Local Variables in Functions
Define local variables in functions the same way you define local variables in the main program.
Refer to Local Variables for more information.
Local variables in the program are different from local variables in functions:
- Local variables in the program retain the value of the variables even after the program terminates. If you call the program again, the variables have the value from the last time the program ran.
- Local variables in the function do not retain the value of the variables. Content of the variables is deleted when the function processes and control passes back to the caller. If you call the function again, the variables have the initialization value.
Return
Use the return keyword to end the function sequence and return to the caller of the function.
The current return values transfer to the caller. In contrast to calling return directly in the program, not all of the program processing is terminated in this case.
Example
program
// program code
endprogram
function real64 result = myFunction(int32 mode, real64 input)
if mode == 1 then
result = -input
return
endif
// more function code
endfunctionIf the mode parameter has a value of 1 in the previous example, the return value result is written with -input. Then, the function evaluation ends. If mode is not equal to 1, the function continues.
Related Information
- Local Variables
Local variables are scoped to a PAscript object. Therefore, you can only access local variables within the block of code that defines the PAscript object.
- Terminate Program Prematurely
Terminate PAscript programs prematurely with return.