How do use boolean? What do && do? and What does == do? Swift 5.1
Booleans are the item that tells weather it’s true or false. For example:
Is it sunny outside could return true or false depending on things.
var canYouSeeTheSun = true var isItBrightOutSide = true if canYouSeeTheSun == true && isItBrightOutSide == true { print("It is suny outside") } else { print("Bad weather today") }
So in the above code we use “==“ double equals to see if a Boolean is true or false.
In the above example we also used the “&&” double ampersand. This will only be true if both booleans in the if statement are true.
When using && and have two conditions these are the results from their values.
Condition A | Condition B | Result |
true | true | true |
true | false | false |
false | true | false |
false | false | false |