Chapter 3. Control Structures

Overview

Program logic is directed by what are called control structures or constructs — statements like if-then-else, do-while, and the like. Rexx offers a complete set of control structures in less than a dozen instructions.

Rexx fully supports structured programming, a rigorous methodology for program development that simplifies code and reduces programmer error. Structured programming restricts control structures to a handful that permit single points of entry and exit to blocks of code. It encourages modularity and reduces complex spaghetti code to short, readable, sections of self-contained code. Small, well-documented routines mean greater clarity and fewer programmer errors. While developer convenience sometimes leads to unstructured code ("Well... it made sense when I wrote it!"), structured, modular code is more readable and maintainable.

We recommend structured programming; nearly all of the examples in this book are structured. But we note that, as a powerful programming language, Rexx includes instructions that permit unstructured coding if desired.

This chapter discusses how to write structured programs with Rexx. We start by listing the Rexx instructions used to implement structured constructs. Then, we describe each in turn, showing how it is used in the language through numerous code snippets. At appropriate intervals, we present complete sample scripts that illustrate the use of the instructions in structured coding.

The latter part of ...

Get Rexx Programmer's Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.