Control Flow Flashcards
Use _____ and _____ to make conditionals,
if, switch
use _____-in, _____, _____, and _____-while to make loops.
for-in, for, while, repeat-while
Parentheses around the condition or loop variable are _____.
optional
An optional value either contains a value or contains nil to indicate that a value is missing. Type _____ after the type of a value to mark the value as optional.
?
var optionalString: String? = “Hello”
_____ support any kind of data and a wide variety of comparison operations—they aren’t limited to integers and tests for equality.
Switches
You use _____ to iterate over items in a dictionary by providing a pair of names to use for each key-value pair.
for-in
_____ are an unordered collection, so their keys and values are iterated over in an arbitrary order.
Dictionaries
Use _____ to repeat a block of code until a condition changes. The condition of a loop can be at the end instead, ensuring that the loop is run at least once.
while
You can keep an index in a loop—either by using _____ to make a range of indexes or by writing an explicit initialization, condition, and increment.
..<
These two loops do the same thing: