Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

explanation of code snippet... 1

Status
Not open for further replies.

GoneHiking

Technical User
Oct 27, 2006
19
US
I'm just starting to learn Rexx, and do NOT come from a programming background, so go easy on me :)

I'd like someone to explain this snippet of code to me. I get that "2" is passed to the ARG statement. What I don't get is the RETURN Code part. The explanation the author gave was that "it returns the value of a variable called RESULT." Huh? How does the variable Code suddenly become Result????


CALL Funct1 2
SAY "Give the funct1 a" 2 "and you get back a" Result
SAY "Give the funct1 a" 4 "and you get back a" Funct1(4)
EXIT 0
Funct1:
ARG Input
Code = Input * 3
RETURN Code
 
You call the function
Code:
   Funct1:
   ARG Input
   Code = Input * 3
   RETURN Code
in your main program which is this
Code:
   CALL Funct1 2
   SAY "Give the funct1 a" 2 "and you get back a" Result
   SAY "Give the funct1 a" 4 "and you get back a" Funct1(4)
   EXIT 0

First you call the function with argument 2 here
Code:
   CALL Funct1 2
When you use the call statement then the result is stored in the special variable RESULT, which holds the value set by a RETURN instruction from
any subroutine.
I'm rather using this way of calling functions
Code:
   my_reslt = CALL Funct1 2
   SAY "Give the funct1 a" 2 "and you get back a" Result

The second call could be clear: You call the function at this way
Code:
Funct1(4)
i.e. with the argument 4 which results in 4*3 = 12.
That's all.
 
mikrom, thanks for the quick reply. This is exactly what I was looking for. It makes sense now. Thanks for breaking it down so clearly!

Andy
 
Oops, In the 4.code windows I have a typo. It should be
Code:
   my_reslt = Funct1(2)
   SAY "Give the funct1 a" 2 "and you get back a" my_reslt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top