Re: IF statement, I don't understand this
- From: "Chuck Stevens" <charles.stevens@xxxxxxxxxx>
- Date: Thu, 30 Mar 2006 08:03:25 -0800
Another mistaken assumption is that abbreviated combined relation conditions
somehow imply a different (and probably higher) precedence from that which
would occur in their fully-expanded counterparts -- that the fact that an
abbreviation occurs in 'ASM010-I-DIR = "L" OR "R" OR "S" ' somehow means
this gets evaluated as a unit (as it might in English). It doesn't. The
abbreviated conditions are treated as if they were expressed in their full
form, and the resulting full conditional expression is then evaluated.
Absent parentheses, it's AND before OR, and otherwise left to right.
Personally, I think abbreviated combined relation conditions are a delusion
and a snare, to be avoided in new code and eliminated from old whenever they
are encountered. They represent a "cute" feature of early COBOL that has
*long* outlived its usefulness, and that (so far as I know) no other
language has seen fit to emulate.
And I also agree that for anything but the most trivial combined relation
conditions (abbreviated or not), the use of parentheses to make the
programmer's intent crystal clear is a really good idea.
-Chuck Stevens
<top post, no more below>
"Howard Brazee" <howard@xxxxxxxxxx> wrote in message
news:49un225ea531sam86depn6i9a2q26fklcg@xxxxxxxxxx
On Thu, 30 Mar 2006 06:40:48 -0600, Jack Benny
<pkline@xxxxxxxxxxxxxxxxxxxxxxxx> wrote:
000600 01 SHH-SHIP-CODE PIC 9 VALUE 1.
000700 01 ASM010-I-DIR PIC X VALUE "R".
and
001000 IF SHH-SHIP-CODE = 5 AND ASM010-I-DIR = "L" OR "R" OR "S"
001100 DISPLAY "TRUE"
001200 ELSE
001300 DISPLAY "FALSE".
001400 ENDIF.
It comes up "TRUE" and I don't understand why. It doesn't seem right.
First, never code complex and/or statements without parentheses. Even
when you understand what is wanted, don't make things hard for
maintenance programmers who need to not only be sure how the code
works, but also be sure how you intended the code to work.
The problem is, you probably assumed that AND and OR are equal,
processed from left to right. That assumption was wrong. AND had
priority.
.
- Follow-Ups:
- Re: IF statement, I don't understand this
- From: Frank Swarbrick
- Re: IF statement, I don't understand this
- From: Howard Brazee
- Re: IF statement, I don't understand this
- References:
- IF statement, I don't understand this
- From: Jack Benny
- Re: IF statement, I don't understand this
- From: Howard Brazee
- IF statement, I don't understand this
- Prev by Date: Re: IF statement, I don't understand this
- Next by Date: Re: IF statement, I don't understand this
- Previous by thread: Re: IF statement, I don't understand this
- Next by thread: Re: IF statement, I don't understand this
- Index(es):