Example
First we create a subroutine that will accept 2 integer values, multiply them and return the result in a variable.
SUBROUTINE DEMO.CALLED.RTN(ARG.1,ARG.2,ARG,3) ARG.3 = ARG.1 * ARG.2 RETURN ENDWhile defining subroutines in Infobasic, we cannot specify which are the incoming and which are the return parameters. Therefore just specify the arguments one after the other along with the subroutine definition as done above. Since the subroutine is storing the result in the variable ARG.3, the system would understand that ARG.3 is the return parameter.
Now let us call the routine we just made.
SUBROUTINE DEMO.CALLING.RTN VAR.1 = 10 VAR.2 = 20 VAR.3 = ‘’ CALL DEMO.CALLED.RTN(VAR.1,VAR.2,VAR.3) PRINT ‘Result “:VAR.3 RETURN END
in this way we can write and call subroutines with arguments.
0 comments:
Post a Comment