Rexx - If statement

The first decision-making statement is the if statement. An if statement consists of a Boolean expression followed by one or more statements.


The general form of this statement in Rexx is as follows −

if (condition) then 

In Rexx, the condition is an expression which evaluates to either true or false. If the condition is true, then the subsequent statements in the loop are executed.

Flow Diagram

The following diagram shows the diagrammatic explanation of this loop.

If Statement

In the above diagram, you can see that only if the condition is evaluated to true does the conditional code gets executed.

The following program is an example of the simple if expression in Rexx.


/* Main program */ 
i = 5 

if (i < 10) then 
      say "i is less than 10" 

The following key things need to be noted about the above program −

  • The if statement is used to first evaluate if the value of i is less than 10.

  • If yes, then the statement inside the do loop is evaluated.

The output of the above program will be −

i is less than 10