Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #11345

Re: behavior of || operator

From Willem <willem@toad.stack.nl>
Newsgroups comp.lang.c
Subject Re: behavior of || operator
Date 2011-10-07 19:50 +0000
Organization Stack Usenet News Service
Message-ID <slrnj8um0i.tkv.willem@toad.stack.nl> (permalink)
References <j6nc0d$dii$1@speranza.aioe.org>

Show all headers | View raw


Mark wrote:
) if ((action != ATTACH) || (action != DETACH))
)     puts("invalid action");

It looks like you don't understand De Morgan's laws.

In English:
If action is not attach or action is not detach, then it is an invalid
action.

What you wanted to do is this:
If action is not attach or detach, then it is an invalid action.

Which is:
 if (!(action == ATTACH || action == DETACH))
     puts("invalid action");

Which, according to De Morgan, is equivalent to:
 if ((action != ATTACH) && (action != DETACH))
     puts("invalid action");


SaSW, Willem
-- 
Disclaimer: I am in no way responsible for any of the statements
            made in the above text. For all I know I might be
            drugged or something..
            No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

behavior of || operator "Mark" <mark_cruzNOTFORSPAM@hotmail.com> - 2011-10-07 13:13 -0400
  Re: behavior of || operator James Kuyper <jameskuyper@verizon.net> - 2011-10-07 14:11 -0400
  Re: behavior of || operator John Gordon <gordon@panix.com> - 2011-10-07 18:47 +0000
  Re: behavior of || operator Willem <willem@toad.stack.nl> - 2011-10-07 19:50 +0000
  Re: behavior of || operator Gene <gene.ressler@gmail.com> - 2011-10-08 13:58 -0700

csiph-web