Conditional Expressions COBOL

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. There are two categories of conditions associated with conditional expressions: simple conditions and complex conditions. Each may be enclosed within any number of paired parentheses, in which case its category is not changed.

Simple Conditions

The simple conditions are relation, class, sign, condition-name and switch-status. A simple condition has a truth value of true or false. A simple condition enclosed in parentheses has the same truth value as the simple condition standing alone.

Relation Condition

A relation condition causes a comparison of two operands, each of which may be the data item referenced by an identifier, a literal, an arithmetic expression or an index-name. A relation condition has the truth value of true if the relation exists between the operands; otherwise, the relation condition has the truth value of false.

The general format of a relation condition is:

Relation Condition

The operand to the left of the relational-operator is called the subject of the condition; the operand to the right is called the object of the condition, or, in the case of the LIKE relational operator, the pattern of the condition.

The general format for the relational-operator is:

general format for the relational-operator

The relational operator specifies the type of comparison to be made in a relation condition. A space must precede and follow each reserved word that makes up the relational operator. When used, NOT and the next keyword or relation character are one relational operator that defines the comparison to be executed for truth value; for example, NOT EQUAL is a truth test for an unequal comparison; NOT GREATER is a truth test for an equal or less than comparison. The relational operator IS NOT GREATER THAN is equivalent to IS LESS THAN OR EQUAL TO, and the relational operator IS NOT LESS THAN is equivalent to IS GREATER THAN OR EQUAL TO.

Comparison of two numeric operands is permitted regardless of the formats specified in their respective USAGE clauses. However, for all other comparisons the operands must have the same usage. If either of the operands is a group item, the nonnumeric comparison rules apply. POINTER usage in RM/COBOL is not a numeric usage; pointer operands may only be compared to other pointer operands, which include the figurative constant NULL (NULLS) and the ADDRESS special register.

The meanings of the relational operators are given in Table.

Relational Operators

Relational Operators

Note:The required relational characters >, < and = are not underlined to avoid confusion with other symbols such as = (greater than or equal to).

Comparison of Numeric Operands

For operands whose class is numeric, a comparison is made with respect to the algebraic value of the operands, aligned by their decimal points. The lengths of the operands, in terms of number of digits represented, are not significant. Zero is considered a unique value regardless of the sign.

Comparison of numeric operands is permitted regardless of their usage. Unsigned numeric operands are considered positive for purposes of comparison.

Comparison of Nonnumeric Operands

For nonnumeric operands, or one numeric and one nonnumeric operand, a comparison is made with respect to a specified collating sequence of characters. When a numeric operand is compared with a nonnumeric operand, the following rules apply:

  1. If the nonnumeric operand is an elementary data item or a nonnumeric literal, the numeric operand is treated as though it were moved to an elementary alphanumeric data item of the same size as the numeric data item (in terms of standard data format characters), and the contents of this alphanumeric data item were then compared to the nonnumeric operand.
  2. If the nonnumeric operand is a group item, the numeric operand is treated as though it were moved to a group item of the same size as the numeric data item (in terms of standard data format characters), and the contents of this group item were then compared to the nonnumeric operand.

The size of an operand is the total number of standard data format characters in the operand. Numeric and nonnumeric operands may be compared only when the numeric operand is an integer and its usage is DISPLAY.

There are two cases to consider: operands of equal size and operands of unequal size.

Operands of equal size:

  • If the operands are of equal size, comparison effectively proceeds by comparing characters in corresponding character positions starting from the high order end and continuing until either a pair of unequal characters is encountered or the low order end of the operand is reached, whichever comes first.The operands are determined to be equal if all pairs of corresponding characters are equal.
  • The first encountered pair of unequal characters is compared to determine their relative position in the collating sequence. The operand that contains the character that is positioned higher in the collating sequence is considered to be the greater operand.

Operands of unequal size:

  • If the operands are of unequal size, comparison proceeds as though the shorter operand were extended on the right by sufficient spaces to make the operands of equal size.

Comparisons of Index-Names and Index Data Items

If two index-names are compared, the result is the same as if the corresponding occurrence numbers were compared.

For an index-name and a data item (other than an index data item) or literal, the comparison is made between the occurrence number that corresponds to the value of the index-name and the data item or literal.

When a comparison is made between an index data item and an index-name or another index data item, the actual values are compared without conversion to the occurrence number.

Comparison of an index data item with any data item or literal not specified above is not permitted.

Comparison of Pointer Data Items

For operands that are pointers, a comparison is made with respect to the effective address of the operands. The effective address of a pointer is the sum of the address and offset values for the pointer. A null pointer value (for example, the figurative constant NULL) has an effective address of zero. Thus, a pointer data item is always either equal to or greater than a null pointer value.

LIKE Condition (Special Case of Relation Condition)

The general format for the LIKE condition is:

LIKE Condition (Special Case of Relation Condition)

identifier-1 must refer to an alphanumeric data item.

literal-1 and literal-2 must be nonnumeric literals.

identifier-2 must refer to an alphanumeric data item or a pointer data item.

The data item referenced by identifier-1 or the value of literal-1 is the subject of the condition.

The data item referenced by identifier-2 or the value of literal-2 is the pattern of the condition. If identifier-2refers to an alphanumeric data item, the value of that data item specifies the pattern as a regular expression. If identifier-2 refers to a pointer data item, then the value of that data item points to a compiled pattern.

The LIKE condition returns true if the subject value of the condition matches the pattern value of the condition and false otherwise.

Unless otherwise specified by use of the TRIMMED phrase, the entire contents of the subject value must match the pattern value. If the TRIMMED LEFT phrase is specified, leading spaces are ignored. If the TRIMMED RIGHT phrase is specified, trailing spaces are ignored. If the TRIMMED phrase is specified without either the LEFT or RIGHT modifiers, leading and trailing spaces are ignored. The TRIMMED phrase must not be used if the subject data may contain significant spaces that would be ignored as a result of its specification; reference modification of the subject may be necessary to select the significant portion of the data to be matched in this case.

Case is significant for the LIKE condition if the CASE-SENSITIVE phrase is specified or implied, that is, a case-sensitive match of the subject value to the pattern value is done. Case is not significant for the LIKE condition if the CASE-INSENSITIVE phrase is specified, that is, a case-insensitive match of the subject value to the pattern value is done.

The pattern may be specified as a literal, an alphanumeric data item, or a pointer data item, with the following interpretations:

  • Literal pattern.The RM/COBOL compiler automatically compiles the pattern specified as literal-2 during source program compilation. Errors in the pattern, if any, are reported in the compilation listing, including an indication of where in the pattern the problem occurred.
  • Alphanumeric data item pattern.The RM/COBOL compiler generates code to compile at runtime a pattern specified as identifier-2, where identifier-2 refers to an alphanumeric data item that contains the pattern. If the data item contains leading or trailing spaces that are not part of the pattern value, reference modification must be used to exclude the spaces. If the pattern contains an error, the LIKE condition will return a false (non-matching) result without any indication that an error occurred. The pattern will be re-compiled each time the condition is executed, regardless of whether the pattern value has changed.
  • Pointer data item pattern. If a pattern must be variable at runtime, but is used multiple times for a given pattern value, compiling the pattern once and specifying a pointer to the compiled result can enhance performance. In this case, the data item referenced by identifier-2 must be a pointer data item, the value of which has been previously set by using the subprogram library routine, C$CompilePattern, as described in Appendix F, Subprogram Library, of the RM/COBOL User’s Guide. When called, this routine indicates whether the pattern contains an error and provides an easy method of stripping trailing spaces in the pattern value. Therefore, this method is preferable to using an alphanumeric data item directly in the LIKE condition regardless of performance issues. The LIKE condition returns a false (non-matching) result if the pattern is specified as a null valued pointer or if the pointer does not point to a compiled pattern.

A pattern is specified by a regular expression. A regular expression is a string that uses expressions similar to arithmetic expressions to specify the rules for matching. Various operators are used to combine smaller expressions. The regular expressions used in the LIKE condition are the same as those specified for XML (eXtensible Markup Language) schema. A regular expression is composed as follows:

  1. Any character other than the special characters specified in item 2 are ordinary characters. An ordinary character is a one-character regular expression that matches itself. For example, "A" matches the string "A" and "3" matches the string "3". Characters may be specified using XML character references as “&#d;”, where d is one or more decimal digits that provide the decimal representation of the Unicode code-point for the character, or as “&#xh;”, where h is one or more hexadecimal digits that provide the hexadecimal representation of the Unicode code-point for the character. Also, the recognized XML entity references are illustrated in Table.
  2. XML Entity References

    XML Entity References

    Recognition and conversion of XML character references and XML entity references occur before a character is interpreted within the regular expression. Incomplete sequences are treated as the literal sequence of characters. For example, “&amp”, which is missing the required semicolon, represents the character sequence ‘&’, ‘a’, ‘m’ and ‘p’. Such incomplete sequences do not cause an error because of the incompleteness, but may cause an error if the literal sequence is not valid in the context in which it appears. For example, “&#x2E;” is equivalent to “.’, which is a valid escaped period, but “&#x2E” includes the sequence “&”, which is not a valid escape sequence and would, therefore, cause an error. No part of the XML character reference or XML entity reference sequence may be represented using an XML character reference or XML entity reference. For example, the sequence “&amp;amp;” is recognized as literally “&amp;” and is not further converted to “&”.

  3. The characters “.” (period), “” (back slash), “*” (asterisk), “+” (plus sign), “?” (question mark), “|” (vertical bar), “(” (left parenthesis), “)” right parenthesis, “[” (left bracket), “]” (right bracket), “{” (left brace), and “}” right brace are special characters that act as operators, which are explained individually in the items that follow.
  4. The special character “.” (period) matches any character other than newline (0Ah) or return (0Dh). For example, "." matches any of the strings "A" or "B" or "9".
  5. The special character “” (backslash) begins an escape sequence. Escape sequences may be single-character escapes (see the following table), multi-character escapes, or category escapes.
  6. Single-character escapes match a single character and exist because that character is usually difficult or impossible to write directly into a regular expression. The valid single-character escapes are shown in Table.

    Regular Expression Single-Character Escape Sequences

    Regular Expression Single-Character Escape Sequences

    Multi-character escapes match commonly used sets of characters without having to write a character class expression to describe the set of characters to be matched. Table lists and describes the valid multi-character escapes.

    Regular Expression Multi-Character Escape Sequences

    Regular Expression Multi-Character Escape Sequences

    Note:The definitions of the “w” and “W” sequences are subject to change, so these sequences should be avoided until they are clarified. The XML schema definition of “w” is unclear because it is described as “all characters except the set of ‘punctuation’, ‘separator’, and ‘control’ characters”.This informal description differs from its formal definition of [&#x00;-&#x10FFFF;]-[p{P}p{S}p{C}], which is all characters except the set of punctuation, symbol and other characters. This could mean that the formal definition should be [&#x0000;-&#x10FFFF;]- [p{P}p{Z}p{C}], [&#x00;-&#x10FFFF;]-[p{P}p{Z}p{Cc}] or [&#x00;- &#x10FFFF;]-[p{P}p{Z}p{S}p{C}].Since “w” probably stands for “the word class of characters”, the latter may be the correct interpretation and is the one currently implemented in RM/COBOL. In the regular expressions of the Perl language, “w” matches alphanumeric characters including “_”, which strictly interpreted would be [p{L}p{N}_]. Unicode classifies “_” in the “Pc” category, so excluding punctuation characters excludes the “_” character. The definition of “W”, the characters not in “w”, depends on the definition of “w” and is, therefore, similarly unclear.

    Note:The B7h code point in Unicode is the “MIDDLE DOT” extender character and is classified as a name character.Therefore, XML name characters include this code point value.

    Category escapes match sets of characters based on their Unicode category. The set of characters that have Unicode property X is designated with “p{ X }”.The complement of this set, that is, all characters that do not have Unicode property X, is specified as “P{ X }”. Unicode property designators are an uppercase letter optionally followed by a lowercase letter. The valid character property designators from the Unicode standard are shown in Table.

    Unicode Valid Character Property Designators

    Unicode Valid Character Property Designators

    For example, the pattern value “p{Nd}” matches any decimal digit character and the pattern value “P{Nd}” matches any character other than a decimal digit character.

    In addition to specifying any of the character property designators above, the character category escape can also specify any of the Unicode character blocks. In this case, the property is specified as Is BlockName, where BlockName is the Unicode block name with all white space stripped out. Since this implementation only supports 8-bit characters, only the character blocks IsBasicLatin (characters 00h through 7Fh) and IsLatin-1Supplement (characters 80h through FFh) are non-empty. For example, the pattern value “p{IsBasicLatin}” matches any character in the range 00h through 7Fh, and the pattern value “P{IsBasicLatin}” matches any character that is not 00h through 7Fh.

  7. The special characters, “[” (left bracket) and “]” (right bracket), are used to define a one-character character class regular expression. The character class matches any of the characters specified between the brackets, except that, when the “^” (caret) character is the first character after the left bracket the class matches any character not specified between the brackets. Special characters (listed in item 2), other than “”, “[”, and “]”, lose their special meaning when contained in brackets (that is, they represent themselves in the character class).A range of characters may be specified with the “-” (hyphen) character separating two other characters. To include a “^” in the character class, include it anywhere except as the first character after the left bracket (if the “^” is the only character in the class, omit the brackets). To include a “-” in the character class, include it as the first (or second if the first character is a “^”) or last character between the brackets or use the escape sequence “-” to specify the character. To include a “”, “[”, or “]” in the character class, use the escape sequences “”, “[”, or “]”, respectively.For example, "[0-9]" matches a decimal digit character and "[^0-9]" matches any character except a decimal digit character. The second character in a hyphenated character range must not be less than the first character.
  8. Within a character class expression, a character class may be subtracted by using the “-” followed by another character class expression. For example, “[p{P}-[;:]]” defines a character class that includes all the punctuation characters except for semicolon and colon. A character class subtraction must be the last portion of a character class expression before the closing “]” for the containing character class expression, but may contain character class subtractions within itself. When a character class is negated, that is, begins with the “^” character, the negation takes place before the subtraction, that is, the negation has higher precedence than the class subtraction. For example, “[^A-F-[U-Z]]”, the characters not in [A-F] less the characters in [U-Z], is equivalent to “[^A-FU-Z]”, the characters not in [A-FU-Z].
  9. Subexpressions may be concatenated by juxtaposition in left to right order. For example, “AB.” matches “ABC” or “ABD” or “AB3” or any other three-character string that begins with “AB”.As another example, “A[BC]D” matches “ABD” or "ACD".
  10. Two subexpressions may be combined with the “|” infix operator to specify alternatives. If either of the subexpressions matches the current position in the subject string, the regular expression formed in this way matches. For example, “PRE|PER” matches “PRE” or “PER”.
  11. The special character “*” causes the preceding subexpression to be matched zero or more times. For example, the string “AB*C” matches “AC” or “ABC” or “ABBBBC”.
  12. The special character “+” causes the preceding subexpression to be matched one or more times. For example, the pattern “$[0-9]+.00” matches the strings “$0.00” or “$1.00” or “$392.00”, but does not match the string “$.00” since there are no digits before the decimal point.
  13. The special character “?” causes the preceding subexpression to be matched zero or one times, that is, the preceding subexpression is optional in matching. For example, the string “-$?123” matches the string “-$123” or “-123”.
  14. The special characters “{” and “}” are used to define repetition of the preceding subexpression by a specified range. “{n}” or “{n,n}” matches exactly n occurrences. “{n,}” matches n or more occurrences. “{n,m}” matches from n to m occurrences. n and m must be decimal integers in the range 0 to 65535, and n must be less than or equal to m. When a choice is allowed, the longest matching string in the subject is matched. For example “(A{2})*” matches zero or more pairs of “A” characters in the subject string, “A{3,}” matches three or more successive “A” characters in the subject string, and “A{3,5}” matches from 3 to 5 successive “A” characters in the subject string.
  15. Note:“{0}” or “{0,0}” cause the previous subexpression to be ignored. “{1}” or “{1,1}” are redundant since they are equivalent to the default. “{0,}” is equivalent to “*”, “{1,}” is equivalent to “+”, and “{0,1}” is equivalent to “?”.

  16. The order of precedence for operators from highest to lowest is escape (with “”), class definition (with “[” and “]”), repetition (with “*”, “+”, “?”, or “{}”), concatenation, and alternation (with “|”). The order of precedence for repetition, concatenation, and alternation can be overridden by use of parentheses. For example:
    • “AB|CD” matches “AB” or “CD”, because concatenation has higher precedence than alternation;
    • “A(B|C)D” matches “ABD” or “ACD”, because the parentheses override the precedence order;
    • “ABC*” matches “ABCCCC”, because repetition has higher precedence than concatenation; and
    • “(ABC)*” matches zero or more occurrences of “ABC” in the subject string, because parentheses override the precedence order.

When the TRIMMED phrase is not specified in the LIKE condition, matching is done on the entire contents of the subject value. In this case, the pattern must specify whether trailing spaces are to be included in the match. If the pattern does not allow for trailing spaces and the subject value contains trailing spaces, the LIKE condition result will be false (non-matching). To allow for trailing spaces, the pattern should end with “ *”, that is, a space followed by the “*” repetition operator. This is not necessary if, for example, the pattern ends with “.*”, that is, a period followed by the “*” repetition operator, since this allows any number of any trailing character, including trailing spaces.

Unicode Valid Character Property Designators

Unicode Valid Character Property Designators

Class Condition

The general format for the class condition is:

Class Condition

The class condition determines whether the current contents of an operand are numeric, alphabetic, alphabetic-lower, alphabetic-upper, or consist only of the characters in the set of characters specified by a CLASS clause defined in the SPECIAL-NAMES paragraph of the Environment Division. The class of an operand is determined as follows:

  • An operand is numeric if its contents consist entirely of the characters 0, 1, 2, 3, . . ., 9, with or without an operational sign.The specified usage of the operand and its explicit or implicit SIGN clause are taken into account in determining the validity of the digit and sign representation.
  • An operand is alphabetic if its contents consist entirely of any combination of the uppercase letters A, B, C, . . ., Z, the lowercase letters a, b, c, . . ., z, or space.It should be noted that this definition of the alphabetic test is not the same as the definition of the alphabetic test in previous versions of COBOL. In order to achieve compatibility with the earlier versions of COBOL, two courses of action are possible: either change the source program to use the alphabetic-upper test in place of the alphabetic test, or make use of the Compile Command option that causes the RM/COBOL compiler to treat alphabetic tests as if they were alphabetic-upper tests.
  • An operand is alphabetic-lower if its contents consist entirely of the lowercase letters a, b, c, . . ., z, or space.
  • An operand is alphabetic-upper if its contents consist entirely of the uppercase letters A, B, C, . . ., Z, or space.
  • An operand fulfills a class-name test if its contents consist entirely of the characters listed in the definition of class-name-1 in the SPECIAL-NAMES paragraph.

When used, NOT and the next keyword specify one class condition that defines the class test to be executed for truth value, for example, NOT NUMERIC is a truth test for determining that an operand is nonnumeric.

The NUMERIC test cannot be used with an item whose data description describes the item as alphabetic.

In the NUMERIC test, the usage of the operand being tested may be DISPLAY, COMPUTATIONAL, COMPUTATIONAL-3 or COMPUTATIONAL-6.

If the usage of the operand being tested is DISPLAY, then:

  1. If the data description of the item being tested indicates the presence of an sign, the item being tested is determined to be numeric only if the operational contents are numeric and a valid operational sign is present. The valid operational signs for numeric DISPLAY data items are defined in the discussion of the SIGN clause and in the discussion of the USAGE clause.
  2. If the data description of the item being tested does not indicate the presence of an operational sign, the item being tested is determined to be numeric only if the contents are numeric and an operational sign is not present.

If the usage of the operand being tested is COMPUTATIONAL, the item being tested is determined to be numeric only if each character position contains an unpacked decimal digit, except that, if the data description of the item being tested indicates the presence of an operational sign, the rightmost character position must contain a valid sign. The representation for a negative sign is hexadecimal D. Depending on configured sign representation, the representation for a positive sign may be hexadecimal C, B, or F.

If the usage of the operand being tested is COMPUTATIONAL-3, the item being tested is determined to be numeric only if each character position, except the rightmost, contains two packed decimal digits. The rightmost character position must contain a packed decimal digit in the high order half-byte and a valid sign in the low order half- byte. The representation for a negative sign is hexadecimal D. Depending on configured sign representation, the representation for a positive sign may be hexadecimal C, B, or F. If the usage of the operand being tested is COMPUTATIONAL-6, the item being tested is determined to be numeric only if each character position contains two packed decimal digits.

The ALPHABETIC test cannot be used with an item whose data description describes the item as numeric. The item being tested is determined to be alphabetic only if the contents consist of any combination of the alphabetic characters and the space. The ALPHABETIC-LOWER test cannot be used with an item whose data description describes the item as numeric. The item being tested is determined to be alphabetic- lower only if its contents consist of any combination of the lowercase alphabetic characters a through z and space.

The ALPHABETIC-UPPER test cannot be used with an item whose data description describes the item as numeric. The item being tested is determined to be alphabetic- upper only if its contents consist of any combination of the uppercase alphabetic characters A through Z and space.

The class-name test must not be used with an item whose data description describes the item as numeric.

Sign Condition

The sign condition determines whether the algebraic value of an arithmetic expression is less than, greater than, or equal to zero. The general format for a sign condition is:

Sign Condition

When used, NOT and the next keyword specify one sign condition that defines the algebraic test to be executed for truth value; for example, NOT ZERO is a truth test for a nonzero value. A value is positive only if it is greater than zero. A value is negative only if it is less than zero. The value zero is neither positive nor negative.

Condition-Name Condition (Conditional Variable)
In a condition-name condition, a conditional variable is tested to determine whether its value is equal to one of the values associated with a condition-name. The general format for the condition-name condition is:

condition-name-1

If condition-name-1 is associated with a range of values, the conditional variable is tested to determine if its value falls within this range, including the end values.

The rules for comparing a conditional variable with a condition-name value are the same as those specified for relation conditions.

The result of the test is true if one of the values corresponding to the condition-name equals the value of its associated conditional variable.

Switch-Status Condition

A switch-status condition determines the on or off status of a software switch. The switch-name and the on or off value associated with the condition must be named in the SPECIAL-NAMES paragraph of the Environment Division. The general format for the switch-status condition is:

condition-name-2

Theresult of the test is true if the switch is set to the specified position corresponding to condition-name-2.

Complex Conditions

A complex condition is formed by combining simple conditions, combined conditions and complex conditions with logical connectors (logical operators AND and OR) or by negating these conditions with logical negation (the logical operator NOT). The truth value of a complex condition, whether parenthesized or not, is the truth value that results from the interaction of the stated logical operators on the individual truth values of the constituent simple conditions.

The logical operators and their meanings are shown in Table.

Logical Operators

Logical Operators

The logical operators must be preceded by a space and followed by a space.

Negated Conditions

A condition is negated by the use of the logical operator NOT, which reverses the truth value of the condition to which it is applied. Thus, the truth value of a negated condition is true only if the truth value of the condition is false; the truth value of a negated condition is false only if the truth value of the condition is true. The inclusion in parentheses of a negated condition does not change the truth value.

The general format for a negated condition is:

NOT condition-1

Combined Conditions

A combined condition results from connecting conditions with one of the logical operators AND or OR. The general format of a combined condition is:

condition-2 and condition-3 may be one of the following:

  • Simple condition.
  • Negated condition.
  • Combined condition.
  • Negated combined condition; that is, the NOT logical operator followed by a combined condition enclosed within parentheses.
  • Combinations of the above.

Although parentheses need never be used when AND or OR (but not both) is used exclusively in a combined condition, parentheses may be used to affect the final truth value when a mixture of AND, OR and NOT is used.

Abbreviated Combined Relation Conditions

When simple or negated simple relation conditions are combined with logical connectives such that a succeeding relation condition contains a subject or subject and relational operator that is common with the preceding relation condition, and no parentheses are used within such a consecutive sequence, any relation condition except the first may be abbreviated by:

  • The omission of the subject of the relation condition
  • The omission of the subject and relational operator of the relation condition

The format for an abbreviated combined relation condition is:

format for an abbreviated combined relation condition

The effect of using such abbreviations is as if the last preceding stated subject were inserted in place of the omitted subject, and the last stated relational operator were inserted in place of the omitted relational operator.

The interpretation applied to the use of the word NOT in an abbreviated combined relation condition is:

  • If the word immediately following NOT is GREATER, >, LESS, <, EQUAL or =, the NOT participates as part of the relational operator.
  • In all other circumstances, the NOT is interpreted as a logical operator and, therefore, the implied insertion of subject or relational operator results in a negated relation condition.

Condition Evaluation Rules

Condition evaluation rules indicate the ways in which conditions and logical operators may be combined and parenthesized. There must be a one-to-one correspondence between left and right parentheses such that each left parenthesis is to the left of its corresponding right parenthesis.

Parentheses may be used to specify the order in which individual conditions of complex conditions are to be evaluated when it is necessary to depart from the implied evaluation precedence. Conditions within parentheses are evaluated first; within nested parentheses evaluation proceeds from the least inclusive condition to the most inclusive condition. When parentheses are not used, or parenthesized conditions are at the same level of inclusiveness, the following hierarchical order of logical evaluation is implied until the final truth value is determined:

  • Truth values for simple conditions are established.
  • Truth values for negated simple conditions are established.
  • Truth values for combined conditions are established AND logical operators followed by OR logical operators.
  • Truth values for negated combined conditions are established.
  • When the sequence of evaluation is not completely specified by parentheses, the order of evaluation of consecutive operations of the same hierarchical level is from left to right

Face Book Twitter Google Plus Instagram Youtube Linkedin Myspace Pinterest Soundcloud Wikipedia

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

COBOL Topics