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

iOS Swift Collections and Control Flow Control Flow With Conditional Statements Recap: Control Flow with Conditional Statements

Martel Storm
Martel Storm
4,157 Points

I don't understand why this statement is true. Can someone please elaborate?

(!true || !false) && (true && !false)

2 Answers

Hiya,

The first parentheses evaluate to true. That's because you are comparing true with false using OR. So, because one of the two comparators is true, the whole parentheses evaluate to true.

The second parentheses also evaluate to true as you are comparing true with NOT false. So, you are comparing true (first parentheses) with true (second parentheses) using AND, which evaluates to true!

I hope that makes sense!

Steve.

Martel Storm
Martel Storm
4,157 Points

This answers my question wonderfully! Thank you!

No problem! :+1: :smile:

andren
andren
28,558 Points

The ! operator essentially reverses a booleans so the first part is essentially this (false || true) since the || operator returns true if either of its conditions are true it will ultimately return true. So the expression on the left of the && operator is true. The expression on the right is essentially (true && true) and the && operator returns true if both of its conditions are true. So the result of the right expression is ultimately true.

That means that after unpacking the right and left expressions you end up with true && true which as mentioned above resolves to true.