Summary -

In this topic, we described about the below sections -

Conditional expression used to select the alternative paths of execution depends on the truth value of condition. Conditional expressions are specified in EVALUATE, IF, PERFORM and SEARCH statements.

Conditional expression can be specified in either simple conditions or complex conditions. Both simple and complex conditions can be enclosed within any number of paired parentheses. The parentheses do not change whether the condition is simple or complex.

Simple conditions -

A simple condition has a truth value of either true or false. There are five simple conditions -

  • Class Condition - The class condition determines whether the content of a data item is alphabetic, alphabetic-lower, alphabetic-upper, numeric or contains only the characters specified by the CLASS clause as defined in the SPECIAL-NAMES paragraph of the environment division.
  • Condition-name Condition - A condition-name condition tests a conditional variable to determine whether its value is equal to any values that are associated with the condition-name.
  • Relation Condition - A relation condition specifies the comparison of two operands. The relational operator that joins the two operands specifies the type of comparison.
  • Sign Condition - The sign condition determines the numeric operand value is positive or negitive. The sign condition also determines whether the algebraic value of a numeric operand is greater than or less than or equal to zero.
  • Switch-status Condition - The switch-status condition determines the on or off status of a UPSI switch (defined in SPECIAL-NAMES paragraph). The switch-status condition tests the value associated with condition-name.

Complex conditions -

A complex condition is formed by combining simple conditions, combined conditions with logical operators or negating those conditions with logical negation. Each logical operator must be preceded and followed by a space. Below table shows the logical operators and their meanings -

Logical operatorNameMeaning
AND Logical conjunction The truth value is true when both conditions are true.
OR Logical inclusive OR The truth value is true when either or both conditions are true.
NOT Logical negation Reversal of truth value (the truth value is true if the condition is false).

The following is the order of precedence (from highest to lowest) unless modified by parentheses -

  • Arithmetic operations
  • Simple conditions
  • NOT
  • AND
  • OR

The below table shows the true value of complex conditions with AND, OR and NOT logical operators -

C1 ValueC2 ValueC1 AND C2C1 OR C2NOT C1NOT C2
True True True True False False
False True False True True False
True False False True False True
False False False False True True

The truth value of a complex condition is the truth value is based on -

  • The individual truth values of simple conditions.
  • The intermediate truth values of conditions logically combined or logically negated.

A complex condition can be either of the following -