Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Does order matter in conditional expressions?

Conditionals

Does order matter in conditional expressions?

by  k5tm  Posted    (Edited  )
Yes, it can matter.

The COBOL standard specifies an order in which the terms of the conditional expression are evaluated. The standard specifies left-to-right evaluation, and further specifies that evaluation terminates as soon as the value of the conditional expression can be determined.

The practical use of this is a situation wherein if the first term is TRUE the evaluation of the second term might result in a runtime error:
Code:
PERFORM A-PARAGRAPH UNTIL
        A-SUBSCRIPT > SUBSCRIPT-LIMIT 
     OR A-TABLE (A-SUBSCRIPT) = SPACES.
In this example, the COBOL standard requires that A-SUBSCRIPT > SUBSCRIPT-LIMIT, the leftmost boolean term, be evaluated first and, if true, terminate evaluation (because the entire expression will be TRUE) before testing A-TABLE (A-SUBSCRIPT), thereby avoiding a potential runtime problem (referring beyond the last item in a table).
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top