Re: IF statement, I don't understand this



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.

.



Relevant Pages

  • Re: and and or priority
    ... David Vallner wrote: ... Why the and and or operators have the same priority? ... Even in programming languages where the rules are clear. ... More parentheses, less readability. ...
    (comp.lang.ruby)
  • parentheses in logic operands
    ... int write_single(int SlaveAddr, int IntAddrSize) ... suggest parentheses around arithmetic in operand of | ... Certainly priority of '&' operation is higher then '|'. ...
    (comp.lang.c)
  • Re: MySQL Fulltext query question
    ... If I'm not mistaken, AND and OR have the same priority, so the condition ... Try grouping the ORs together with ... parentheses like this: ... WHERE MATCH (ResourceDescription) AGAINST ...
    (comp.lang.php)
  • Re: 1000-200*4% add
    ... [I have included parentheses to make it clear ... to you what the priority of the arithmetic operations will be, ... David Biddulph ...
    (microsoft.public.excel.misc)