Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Multiple numeric not or compare in if statement

by syphilis (Archbishop)
on Jul 02, 2020 at 05:08 UTC ( [id://11118784]=note: print w/replies, xml ) Need Help??


in reply to Multiple numeric not or compare in if statement

if (($a != 3) || ($a != 77) || ($a != 8))

Try instead:
if (($a != 3) && ($a != 77) && ($a != 8))

Cheers,
Rob

Replies are listed 'Best First'.
Re^2: Multiple numeric not or compare in if statement
by perlfan (Vicar) on Jul 02, 2020 at 05:32 UTC
    OP: maybe it was an oversight, but when changing the nested logic in a condition such as that you must necessarily change the higher level logic if you wish for the original to be equivalent exactly opposite to the negated version.

    if (($a == 3) || ($a == 77) || ($a == 8)) -- is exactly opposite to -- if (($a != 3) && ($a != 77) && ($a != 8))

    Update: correct - meant to show exact opposites, used the most wrong possible to describe this.

      if (($a == 3) || ($a == 77) || ($a == 8)) -- is equivalent to -- if (($a != 3) && ($a != 77) && ($a != 8))

      No, those two aren't equivalent, they're exact opposites. It seems you didn't apply what you said:

      when changing the nested logic in a condition such as that you must necessarily change the higher level logic if you wish for the original to be equivalent to the negated version.
      if (($a == 3) || ($a == 77) || ($a == 8)) -- is equivalent to -- if (!( ($a != 3) && ($a != 77) && ($a != 8) ))
        Thanks, updated. Meant to show the exact opposite; said the opposite thing instead.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11118784]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-25 10:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found