473,776 Members | 1,572 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Boolean Confusion

RMWChaos
137 New Member
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 1084
RMWChaos
137 New Member
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 Recognized Expert Moderator Expert
hi ...

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

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

Similar topics

2
6928
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 a type mismatch. It is positively because of the boolean(java primitive)parameter. It goes fine if I change this parameter to int or String. This inteface has a lot more methods which works fine, it is just the
10
8623
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; boolean x; x=1;
16
17543
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 Jyväskylä, Finland "Very funny scotty, now beam down my clothes." GCS d- s+: a--- C++>$ L+>+++$ E- W+ N+ !o>+ w---
10
13829
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 Nothing). But Boolean is a Structure in VB.NET (defined to False by default) and not an Object so I'm afraid there's no way to do what I want without any workaround. Can you confirm that there's no object version of Boolean in VB.NET? Thanks
1
3181
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 between projects in the solution were established through project references, not by browsing to an assembly DLL. All of the projects are strongly named and use key files. Each project's AssemblyInfo.cs specifies the assembly version, where the...
10
16430
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 recognized as a valid Boolean. Public Sub UpdateCustomer_DashboardGraphs(ByVal sender As Object, ByVal e As System.EventArgs)
76
4930
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 uppercase 'B' anyway?) and the header you can include (apparently) to get a real "bool". This isn't my point, however -- it should have been there from the beginning. char is a small int. We all know that. However, "char some_bool = 0;" simply...
4
306
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 in 5.10 Boolean operations: " The expression x and y first evaluates x; if x is false, its value is
7
1745
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 and unions are supposed to be done like this: In :set('casa') & set('porca') Out:set() In :set('casa') | set('porca')
0
9464
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10289
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10120
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9923
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7471
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5493
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4031
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3622
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2860
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.