Conditions Flashcards
What is a Boolean type in Swift?
A Boolean type returns a value of either true or false.
Example in Swift:
let isLoggedIn = true
What does the ‘equal to’ (==) operator do?
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
What does the ‘greater than’ (>) operator do?
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
What does the ‘less than’ (<) operator do?
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
What does the ‘greater than or equal to’ (>=) operator do?
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
What does the ‘less than or equal to’ (<=) operator do?
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
What does the ‘not equal to’ (!=) operator do?
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
What is the logical AND (&&) operator?
The logical AND operator returns true if both conditions are true.
Example in Swift:
let result = (5 > 3 && 10 > 7) // true
What is the logical OR (||) operator?
The logical OR operator returns true if at least one condition is true.
Example in Swift:
let result = (5 > 3 || 3 > 10) // true
What is the NOT (!) operator?
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
What is the Exclusive OR (XOR) operator?
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
What is encryption?
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.
What is an if statement in Swift?
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!”)
}
What is an else statement in Swift?
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!”)
}
What is an else-if statement in Swift?
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.”)
}