Conditional expressions identify conditions that are tested to enable the object program to select between alternate paths of control depending upon the truth value of the condition. Conditional expressions may be used in the EVALUATE, IF, PERFORM, and SEARCH statements. Conditional expressions have a value of “TRUE” or “FALSE”. Conditional expressions can either be simple or complex. There are various types of Conditional statements in Cobol :
A relation condition specifies a comparison of two operands, each of which may be a data item or a literal. Comparison between operand/s or literal/s can be done using relational operators i.e. < , > , < = , >= , ==. We can either use the particular relational symbol or we can spell it out in words.
VALUE-1 IS [NOT] { GREATER THAN } VALUE-2 { > } { LESS THAN } { < } { EQUAL TO } { = } { <> } { GREATER THAN OR EQUAL TO} { >= } { LESS THAN OR EQUAL TO } { <= }
Meaning | Operators |
Greater than | IS GREATER THAN IS > IS NOT <= IS NOT LESS THAN OR EQUAL TO |
Equal to | IS EQUAL TO IS = |
Less than | IS LESS THAN IS < IS NOT >= IS NOT GREATER THAN OR EQUAL TO |
Greater than or equal | IS NOT LESS THAN IS NOT < IS >= IS GREATER THAN OR EQUAL TO |
Not equal to | IS NOT EQUAL TO IS NOT = IS <> |
Less than or equal | IS NOT GREATER THAN IS NOT > IS <= IS LESS THAN OR EQUAL TO |
IS not like | IS NOT LIKE |
The class condition tests whether or not an operand contains a particular type of data. The format of a class condition is:
Arithmetic-expression IS [NOT] {POSITIVE} {NEGATIVE} {ZERO }
An arithmetic expression is POSITIVE if it is greater than zero, NEGATIVE if it is less than zero. If the NOT option is specified, the truth value of the test is reversed.
A complex condition is formed by combining conditions (either simple or complex) with logical connectors (AND and OR) or by negating these conditions with logical negation (NOT). The truth value of a complex condition depends on the interaction of the logical operators and their component conditions.
The logical operators and their meanings are:
Operator | Meaning |
AND | true when both components true |
OR | true when either component true |
NOT | true when condition false |
A condition is negated by the logical operator NOT, which reverses the truth value of the condition to which it is applied. In other words, a negated condition is true when its component condition is false, and is false when its component condition is true. The format of a negated condition is:
NOT condition
A combined condition results from connecting conditions with one of the logical operators AND or OR. The general format is:
condition { {AND} condition } ... {OR }
In the general format, the condition may be any of the following:
Parentheses may be used in complex conditions to alter the rules of evaluation. Parentheses must be made in matched pairs and must be placed in such a way that the enclosed symbols constitute a well-defined condition.
The truth value of a combined condition using AND is true only when both component conditions are true. The truth value of a combined condition using OR is true when either or both of the component conditions are true.
When simple or negated simple conditions are combined in a consecutive sequence, the relation conditions may be abbreviated. You can do this by either:
The format for an abbreviated combined relation condition is:
condition { {AND} [NOT] [relation] object } ... {OR }
Within a sequence of relation conditions, both of the above forms of abbreviation may be used. When you use such abbreviations, it is as if the last preceding stated subject was inserted in the place of the omitted subject, and the last stated relational operator was inserted in the place of the omitted relational operator. The insertion of an omitted subject or relational operator terminates once a complete simple condition is encountered within a complex condition. Except for the source of the initial relation condition, no parentheses may appear in the sequence of abbreviated conditions.
If the word NOT is used in an abbreviated combined relation condition, it has the following meaning:
The following are examples of abbreviated combined relation conditions and their expanded equivalents:
A > B AND NOT < C (A > B) AND (A NOT < C) A NOT = B OR C (A NOT = B) OR (A NOT = C) NOT A = B OR C (NOT (A = B)) OR (A = C) NOT (A > B OR < C) NOT ((A > B) OR (A < C))
A condition is evaluated according to the following hierarchy:
Here are some examples of equivalent conditions:
NOT A AND B OR C AND D ((NOT A) AND B) OR (C AND D) NOT A AND B AND C ((NOT A) AND B) AND C A AND B OR NOT (C OR D) (A AND B) OR (NOT (C OR D)) NOT ( NOT A OR B OR C ) NOT ( ((NOT A) OR B) OR C )
Evaluation of a condition halts as soon as its truth value is determined. For example, in conditions A AND B, condition `B’ would not be evaluated if `A’ were false.
A well-maintained product backlog is crucial for successful product development. It serves as a single…
Incremental value to the customer refers to the gradual delivery of small, functional parts of…
A Product Market refers to the group of potential customers who might be interested in…
The Professional Agile Leadership - Evidence-Based Management (PAL-EBM) certification offered by Scrum.org is designed for…
The Professional Agile Leadership (PAL I) certification, offered by Scrum.org, is designed to equip leaders…
Choosing the right Scrum Master Certification depends on your current experience and career goals. If…