Conditions Flashcards

1
Q

What is a Boolean type in Swift?

A

A Boolean type returns a value of either true or false.
Example in Swift:
let isLoggedIn = true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does the ‘equal to’ (==) operator do?

A

The ‘equal to’ operator checks if two values are equal, returning true if they are equal and false if they are not.
Example in Swift:
let isEqual = (5 == 5) // true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does the ‘greater than’ (>) operator do?

A

The ‘greater than’ operator checks if the value on the left is greater than the value on the right.
Example in Swift:
let isGreater = (10 > 5) // true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does the ‘less than’ (<) operator do?

A

The ‘less than’ operator checks if the value on the left is less than the value on the right.
Example in Swift:
let isLess = (3 < 5) // true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does the ‘greater than or equal to’ (>=) operator do?

A

The ‘greater than or equal to’ operator checks if the value on the left is greater than or equal to the value on the right.
Example in Swift:
let isGreaterOrEqual = (5 >= 5) // true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does the ‘less than or equal to’ (<=) operator do?

A

The ‘less than or equal to’ operator checks if the value on the left is less than or equal to the value on the right.
Example in Swift:
let isLessOrEqual = (5 <= 10) // true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does the ‘not equal to’ (!=) operator do?

A

The ‘not equal to’ operator checks if two values are not equal, returning true if they are not.
Example in Swift:
let isNotEqual = (5 != 3) // true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the logical AND (&&) operator?

A

The logical AND operator returns true if both conditions are true.
Example in Swift:
let result = (5 > 3 && 10 > 7) // true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the logical OR (||) operator?

A

The logical OR operator returns true if at least one condition is true.
Example in Swift:
let result = (5 > 3 || 3 > 10) // true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the NOT (!) operator?

A

The NOT operator inverts the Boolean value, returning true if it was false, and false if it was true.
Example in Swift:
let isFalse = !(5 == 5) // false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the Exclusive OR (XOR) operator?

A

The Exclusive OR (XOR) operator returns true if exactly one of the conditions is true, but false if both are true or both are false.
Example in Swift:
let result = (true ^ false) // true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is encryption?

A

Encryption is the process of converting information into scrambled code to protect it from unauthorized access.
Example:
When paying online, encryption secures your payment details.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is an if statement in Swift?

A

An if statement checks a condition and executes a block of code if the condition is true.
Example in Swift:
let isRaining = true
if isRaining {
print(“Bring an umbrella!”)
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is an else statement in Swift?

A

An else statement runs a block of code if the condition in the if statement is false.
Example in Swift:
let isRaining = false
if isRaining {
print(“Bring an umbrella!”)
} else {
print(“No need for an umbrella!”)
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is an else-if statement in Swift?

A

An else-if statement is used to check additional conditions after the initial if condition.
Example in Swift:
let position = 2
if position == 1 {
print(“You came first!”)
} else if position == 2 {
print(“You came second!”)
} else {
print(“You did not finish in the top two.”)
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How are Booleans used in conditional statements?

A

Booleans evaluate to either true or false and are used to determine if a condition is met.
Example in Swift:
let coldOutside = true
if coldOutside {
print(“Put on a warm coat.”)
}

17
Q

How does the logical AND (&&) operator work in Swift?

A

The AND (&&) operator returns true if both sides of the condition are true.
Example in Swift:
let temp = 70
if temp >= 68 && temp <= 72 {
print(“The temperature is just right!”)
} else {
print(“The temperature is too hot or too cold.”)
}

18
Q

How does the logical OR (||) operator work in Swift?

A

The OR (||) operator returns true if at least one side of the condition is true.
Example in Swift:
let mainsPower = false
let batteryPower = true
if mainsPower || batteryPower {
print(“I can use my phone!”)
} else {
print(“Better find a charger.”)
}