473,327 Members | 2,094 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Boolean Confusion

RMWChaos
137 100+
My brain is fried from looking at way too much code lately. So help me understand, if you will, do these operators:

Expand|Select|Wrap|Line Numbers
  1. if (A && B || C)
  2.  
mean, "If either A and B are true or if C is true"?

And then this operation:

Expand|Select|Wrap|Line Numbers
  1. if (A && B || A && C)
  2.  
mean, " If either A and B is true or A and C is true"?

In other words, these two statements above are not the same, correct?

If the above is all correct, then is there a way with the second statement to not have to repeat A? Maybe it's like this:

Expand|Select|Wrap|Line Numbers
  1. if (A &| B || C)
  2.  
No, that sounds more like, "If A is true, or A and B is true, or C is true." So maybe like this:

Expand|Select|Wrap|Line Numbers
  1. if (B &| A &| C)
  2.  
No again. That means, "If B is true, or B and A is true, or A is true, or A and C is true, or C is true. Whew! Well that covers the gamut, so I know for the future. Oh wait, it didn't cover if B and C is true! =D

Alright, I give! So is there even a way to write "A&B or A&C" without have to write A twice? I guess at this point, after all this mess, it probably doesn't matter. Sigh.

Man, even asking questions about boolean operators is tough. No wonder I have so much trouble understanding them.
Oct 27 '07 #1
2 1056
RMWChaos
137 100+
Wait, I might have it here. Rather than what I wrote above, should I write it like this to avoid boolean confusion?

Expand|Select|Wrap|Line Numbers
  1. if ((A && B) || (A && C))
  2. // "If A and B or if A and C".
  3.  
  4. if((A && B) || C)
  5. // "If A and B or if C".
  6.  
  7. if (A && (B || C))
  8. // AHA! "If A and either B or C"!
  9. // Also can be written, "If A and B or if A and C".
  10. // Ta-da! =D
  11.  
I think I am getting the hang of this now. Someone just clue me in that I am on the right track.

Thanks for putting up with my ramblings...I'm a part-time writer; so "writing out loud" like this helps me work through problems. And just maybe it will help someone else too, I can always hope.
Oct 27 '07 #2
gits
5,390 Expert Mod 4TB
hi ...

:) you got it ...
Oct 27 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Eyal | last post by:
Hey, I would appriciate if anyone can help on this one: I have a java object/inteface having a method with a boolean parameter. As I'm trying to call this method from a javascript it fails on...
10
by: Ramprasad A Padmanabhan | last post by:
Hello all, On my linux box ( redhat 7.2 ), I have been using char as a boolean data type. In order to save on the number of bytes as compared to using int or short int. typedef char boolean;...
16
by: Ian Tuomi | last post by:
How can I define a boolean value in c? (an value that can only be either 1 or 0) I feel bad for the memory loss when declaring ints for variables that do not need that much memory. -- Ian Tuomi...
10
by: Henri | last post by:
In java for instance there's a way to use booleans as objects and not as value types. I would like to do the same in VB.NET so that I can check if the boolean has been explicitely defined (is not...
1
by: Richard Lewis Haggard | last post by:
I'm having a problem with what appears to be some sort of confusion with references. I have a single solution with a dozen projects which has been working quite nicely for a while. The references...
10
by: dba123 | last post by:
Why am I getting this error for Budget? Error: An exception of type 'System.FormatException' occurred in mscorlib.dll but was not handled in user code Additional information: String was not...
76
by: KimmoA | last post by:
First of all: I love C and think that it's beautiful. However, there is at least one MAJOR flaw: the lack of a boolean type. OK. Some of you might refer to C99 and its _Bool (what's up with the...
4
by: Greg Corradini | last post by:
Hello all, I'm having trouble understanding why the following code evaluates as it does: True -1 In the 2.4 Python Reference Manual, I get the following explanation for the 'and' operator...
7
by: Flavio | last post by:
Hi, I have been playing with set operations lately and came across a kind of surprising result given that it is not mentioned in the standard Python tutorial: with python sets, intersections ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.