পৃষ্ঠাসমূহ

Search Your Article

CS

 

Welcome to GoogleDG – your one-stop destination for free learning resources, guides, and digital tools.

At GoogleDG, we believe that knowledge should be accessible to everyone. Our mission is to provide readers with valuable ebooks, tutorials, and tech-related content that makes learning easier, faster, and more enjoyable.

What We Offer:

  • 📘 Free & Helpful Ebooks – covering education, technology, self-development, and more.

  • 💻 Step-by-Step Tutorials – practical guides on digital tools, apps, and software.

  • 🌐 Tech Updates & Tips – simplified information to keep you informed in the fast-changing digital world.

  • 🎯 Learning Support – resources designed to support students, professionals, and lifelong learners.

    Latest world News 

     

Our Vision

To create a digital knowledge hub where anyone, from beginners to advanced learners, can find trustworthy resources and grow their skills.

Why Choose Us?

✔ Simple explanations of complex topics
✔ 100% free access to resources
✔ Regularly updated content
✔ A community that values knowledge sharing

We are continuously working to expand our content library and provide readers with the most useful and relevant digital learning materials.

📩 If you’d like to connect, share feedback, or suggest topics, feel free to reach us through the Contact page.

Pageviews

Monday, February 6, 2017

Rexx - Functions

The code in Rexx is normally divided into Functions and Subroutines. Using functions helps in segregating the code into many more logical units. Let’s look at these functions in detail.

Defining a Function

The syntax of a function declaration is as follows −
FunctionName: 
PARSE ARG arguement1, arguement2… arguementN 
Return value 
Where,
  • FunctionName − This is the name assigned to the function.
  • PARSE ARG − These are keywords in Rexx which are used to mention that parameters are being passed onto the function.
  • arguement1, arguement2… arguementN − These are the arguments passed to the function.
  • Return value − This is the value returned by the function.
The following program is a simple example of how functions are used in Rexx.
/* Main program */ 
say add(5,6) 
exit 
add: 
PARSE ARG a,b 
return a + b 
The following things should be noted about the above program −
  • We are defining a function called add which accepts 2 parameters a and b.
  • The function uses the return statement to return the sum of a and b.
  • The exit statement has to be used to signify the end of the main program.
The output of the above program would be as follows −
11

Working with Arguments

In Rexx, there are specific functions which can be made to work with arguments. Let’s look at a couple of such arguments.

arg

This method is used to return the number of arguments defined for the function.
Syntax
arg() 
Parameters − None
Return Value − This method returns the number of arguments defined for the function.
Example
/* Main program */ 
say add(5,6) 
exit 
add: 
PARSE ARG a,b 

say arg() 
return a + b 
Output − When we run the above program we will get the following result.
2 
11 

arg(index)

This method is used to return the value of the argument at the specific position.
Syntax
arg(index)
Parameter
  • Index − Index position of the argument to be returned.
Return Value − This method returns the value of the argument at the specific position.
Example
/* Main program */ 
say add(5,6) 
exit 
add: 
PARSE ARG a,b 

say arg(1) 
return a + b 
Output − When we run the above program we will get the following result.
5 
11 

Recursive Functions

A recursive function or routine is one that calls itself. Any recursive function could be coded in a traditional non-recursive fashion (or iteratively), but sometimes recursion offers a better problem solution. Not all programming languages support recursion; Rexx does.
Let’s see an example of the famous factorial program using recursive functions in Rexx.
/* Main program */ 
do n = 1 to 5 
say 'The factorial of' n 'is:' factorial( n ) 
end 
return  

/* Function to get factorial */ 
factorial : procedure 
n = arg(1) 
if n = 1 then 
return 1 
return n * factorial( n - 1 ) 
The output of the above program is as follows −
The factorial of 1 is: 1
The factorial of 2 is: 2 
The factorial of 3 is: 6 
The factorial of 3 is: 24 
The factorial of 3 is: 120 

No comments:

Post a Comment