Passing and Returning Values
Procedures do not normally have access to variables outside of their main body. In order to give values to variables they can be passed to the procedure when it is called. ... Test(5,n,"Bob") ... Procedure Test( int number, int otherNumber, string name) ... End Proc Inside the procedure Test: - The variable number will contain the value 5. - The variable otherNumber will contain the same value of n - The variable string$ will contain the value of string$ from the main body of code. The variables inside Test can be changed and used just like all the other variables inside Test. If the values of the variables are changed they do not affect the values in the main body of code. Returning Values
Procedures can return values to the point in the code from which they were called. e.g. ' Main code ... Test() Print Result Int ... ' Procedure definition Procedure Test() ... End Proc(n) The procedure Test can change the value of n and return it. This value can then be caught from the point the procedure was called from using the Result command. Result Int/Result Integer contains the returned value if the value specified was an integer. Result Float contains the returned value if the value specified was an floating point number. Result Str/Result String contains the returned value if the value specified was a string.
Table of contents