Rexx - If statement


Advertisements

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

Syntax

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

if (condition) then 
   do 
      #statement1 
      #statement2 
   end

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.

Example

/* Main program */ 
i = 5 

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

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 
rexx_decision_making.htm
Advertisements