Monday, 28 July 2014

COBOL Negative Condition.

A simple condition is negated through the use of the logical operator NOT.

Format :        IF EMP-NO NOT EQUALS TO 20010

The negated simple condition gives the opposite truth value of the simple condition. 

That is, if the truth value of the simple condition is true, then the truth value of that same negated simple condition is false, and vice versa. Placing a negated simple condition within parentheses does not change its truth value. 

That is, the following two statements are equivalent:

  1. NOT ITEM-A IS EQUAL TO ITEM-B.
  2. NOT (ITEM-A IS EQUAL TO ITEM-B).

Two or more conditions can be logically connected to form a combined condition.

  • A simple-condition
  • A negated simple-condition
  • A combined condition
  • A negated combined condition (that is, the NOT logical operator followed by a combined condition enclosed in parentheses)

Parentheses are never needed when either ANDs or ORs (but not both) are used exclusively in one combined condition. However, parentheses might be needed to modify the implicit precedence rules to maintain the correct logical relation of operators and operands.

Order of evaluation of conditions

Parentheses, both explicit and implicit, define the level of inclusiveness within a complex condition. Two or more conditions connected by only the logical operators AND or OR at the same level of inclusiveness establish a hierarchical level within a complex condition. Therefore an entire complex condition is a nested structure of hierarchical levels, with the entire complex condition being the most inclusive hierarchical level.

Within this context, the evaluation of the conditions within an entire complex condition begins at the left of the condition. The constituent connected conditions within a hierarchical level are evaluated in order from left to right, and evaluation of that hierarchical level terminates as soon as a truth value for it is determined, regardless of whether all the constituent connected conditions within that hierarchical level have been evaluated.


Created with Artisteer

No comments:

Post a Comment