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

  1. Open a Text Editor:

    • You can use any text editor of your choice (e.g., Notepad, Notepad++, VS Code).
  2. Write the Code:

    • Type the following code into your text editor:
/* Hello World Program in REXX */
say "Hello, World!"
  1. Save the File:

    • Save the file with a .rexx or .rex extension, for example, hello.rexx.
  2. 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:
rexx hello.rexx

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.
  • 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!".

Practical Exercise

Task

Write a REXX program that prints "Welcome to REXX Programming!" to the screen.

Solution

  1. Open a Text Editor:

    • Use any text editor of your choice.
  2. Write the Code:

    • Type the following code:
/* Welcome Program in REXX */
say "Welcome to REXX Programming!"
  1. Save the File:

    • Save the file with a .rexx or .rex extension, for example, welcome.rexx.
  2. 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:
rexx welcome.rexx

Common Mistakes and Tips

  • File Extension:

    • Ensure the file is saved with the correct extension (.rexx or .rex).
  • Syntax Errors:

    • Make sure there are no typos in the say statement or the string to be printed.
  • 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.

© Copyright 2024. All rights reserved