Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C# C# Objects Methods Methods

Grigor Samvelian
Grigor Samvelian
2,852 Points

conditional-or operator question

Hi, in the teachers notes of the video Methods | C# Objects its stated in the truth table of the conditional-or operator that if x is false and y is true the result would be true, but from my understanding of the conditional-or operator that the answer should be false because x is false and x is evaluated first. Could someone please explain to me why the result would be true, thank you!

Christian ROLLET
Christian ROLLET
11,252 Points

Hi

x||y is true if x is true x||y is true if y is true x||y is false if x is false AND y is false.

With conditional or, if x is false, then y is evaluated , because if x is false, to know what is the value of x||y, you need to to know the value of y) BUT if x is true, then the value of y is not evaluated, because if x is true, x||y is always true; either y is false or true.

Hope this help

1 Answer

Tsenko Aleksiev
Tsenko Aleksiev
3,819 Points

AND - both sides of the operator must be true in order the result to be true. If only one side is false, than the result is false. OR - it needs only one side if the operator, no matter which one, to be true in order the result to be true. If both are false, only than the result is going to be false. Think of it: Bodyguard at the entrance of a disco: he only passes if you are a boy AND you have 18. The next day he passes only if you have 18 OR you a dressed as a cloun. Got it?

Grigor Samvelian
Grigor Samvelian
2,852 Points

ah so doesn't matter where and when true is stated, if its stated then the result will be true?

Tsenko Aleksiev
Tsenko Aleksiev
3,819 Points

Using the OR operator - yes, doesn’t matter which side is true, you need only one true and the whole result is true. The program checks the first side, it’s false, well let me check the other side - huh it’s true, so I will return true. The other way: I will check first side, oh it’s true, so I don’t care what’s the other part, I have what I need - the reault it’s true. :)