Introduction
In this section, we will write our first REXX program: the classic "Hello, World!" example. This simple program will help you understand the basic structure and syntax of REXX.
Writing the "Hello, World!" Program
Step-by-Step Guide
-
Open a Text Editor:
- You can use any text editor of your choice (e.g., Notepad, Notepad++, VS Code).
-
Write the Code:
- Type the following code into your text editor:
-
Save the File:
- Save the file with a
.rexx
or.rex
extension, for example,hello.rexx
.
- Save the file with a
-
Run the Program:
- Open your command line interface (CLI) or terminal.
- Navigate to the directory where you saved your
hello.rexx
file. - Execute the program by typing the following command:
Explanation of the Code
-
Comment:
/* Hello World Program in REXX */
- Comments in REXX are enclosed within
/*
and*/
. They are ignored by the interpreter and are used to provide explanations or notes within the code.
- Comments in REXX are enclosed within
-
Output Statement:
say "Hello, World!"
- The
say
instruction is used to display text or variables to the standard output (usually the screen). In this case, it prints the string"Hello, World!"
.
- The
Practical Exercise
Task
Write a REXX program that prints "Welcome to REXX Programming!" to the screen.
Solution
-
Open a Text Editor:
- Use any text editor of your choice.
-
Write the Code:
- Type the following code:
-
Save the File:
- Save the file with a
.rexx
or.rex
extension, for example,welcome.rexx
.
- Save the file with a
-
Run the Program:
- Open your CLI or terminal.
- Navigate to the directory where you saved your
welcome.rexx
file. - Execute the program by typing the following command:
Common Mistakes and Tips
-
File Extension:
- Ensure the file is saved with the correct extension (
.rexx
or.rex
).
- Ensure the file is saved with the correct extension (
-
Syntax Errors:
- Make sure there are no typos in the
say
statement or the string to be printed.
- Make sure there are no typos in the
-
Running the Program:
- Ensure you are in the correct directory in the CLI or terminal before running the program.
Summary
In this section, you learned how to write and execute a simple "Hello, World!" program in REXX. You also practiced writing a similar program to print a different message. This foundational knowledge will help you as you progress through more complex REXX programming concepts.
REXX Programming Course
Module 1: Introduction to REXX
- What is REXX?
- Setting Up the REXX Environment
- Hello World in REXX
- Basic Syntax and Structure
- Variables and Data Types
Module 2: Basic Programming Concepts
- Operators and Expressions
- Control Structures: IF/THEN/ELSE
- Loops: DO and LEAVE
- Input and Output
- Basic String Manipulation
Module 3: Intermediate REXX Programming
Module 4: Advanced REXX Programming
- Advanced String Manipulation
- Parsing Techniques
- Interfacing with External Programs
- REXX Macros
- Performance Optimization