Getting Started with App Development [Section 5: Control Flow] Flashcards
code that makes decisions about what lines of code should be executed depending on results of previously executed code is called _________ ________
control flow
Operator:
==
Type: Comparison
Description: Two items must be equal
Operator:
!=
Type: Comparison
Description: The values must not be equal to each other
Operator:
>
Type: Comparison
Description: Value on the left must be greater than the value on the right
Operator:
> =
Type: Comparison
Description: Value on the left must be greater than or equal to the value on the right
Operator:
<
Type: Comparison
Description: Value on the left must be less than the value on the right
Operator:
<=
Type: Comparison
Description: Value on the left must be less than or equal to the value on the right
Operator:
&&
Type: Logical
Description: AND — the conditional statement on the left AND right must be true
Operator:
||
Type: Logical
Description: OR — the conditional statement on the left OR right must be true
Operator:
!
Type: Logical
Description: NOT — returns the logical opposite of the conditional statement immediately following the operator
An ____ ________ states that “if this condition is true, then run this block of code”
if statement
let temperature = 32
if temperature >= 32 {
print(”The water is boiling.”)
}
Console Output:
The water is boiling.
By adding an ______ _________ to an if statement, you can specify a block of code to execute if the condition is not true
else clause
e.g.,
let temperature = 32
if temperature >= 32 {
print(”The water is boiling.”)
} else {
print(”The water is not boiling.”)
}
Via using ______ _______, you can declare more blocks of code to run based on any number of conditions
else if
e.g.,
var finishPosition = 2
if finishPosition == 1 {
print(”Congratulations, you won the gold medal!”)
} else if finishPosition == 2 {
print(”You came in second place, you won a silver medal!”)
} else {
print(”You did not win a gold or silver medal.”)
}
It’s possible to invert a ______ value using the logical NOT operator, which is represented with “!”
Bool
e.g.,
var isSnowing = false
if !isSnowing {
print(”It is not snowing.”)
}
Console Output:
It is not snowing.
You can also use the logical AND operator, represented by ____, to cheque if two or more conditions are true
&&
e.g.,
let temperature = 70
if temperature >= 65 && temperature <= 75 {
print(”The temperature is just right.”)
} else if temperature < 65 {
print(”It is too cold.”)
} else {
print(”It is too hot.”)
}
Console Output:
The temperature is just right.