Give 3 examples of commands!
Any of the 3: moveForward(), turnLeft(), turnRight(), toggleSwitch(), collectGem(),
How do we declare a for loop?
for
What is a term that will states the answer is true or false?
Boolean
What are the 3 logical operators?
" || ", " && ", " ! " (OR, AND, NOT)
How do we define a while loop?
while
What do you call a collection of commands that are grouped together and given a name?
Function
How many times does a for loop run for?
Whatever the end number/end condition is that we state
How will a conditional code run?
If the condition is true
How many conditions need to be true when using &&?
All conditions
What do you call a loop that never ends?
Infinite loop
What is the code to delcare a function?
func
What is the term for using a loop inside another loop?
Nesting
What are the 3 conditionals we use?
if, else-if, and else
How many conditions need to be true when using " || "?
At least 1 condition.
How do we define the end of a while loop?
When the condition is false
What is one reason we might define a function?
Reusability, clean code, short code, condensed code
What type of situation would we use a for loop?
When we want to repeat the code for the exact number of times, consecutively.
In Playgrounds, what is the starting word for a condition?
What does the following logical operator do: " ! "?
The opposite of the condition must be true to run.
When will you use a while loop rather than a for loop?
When you do not know how many times to run your loop
What characters are used to contain a block of code?
Curly Braces/Brackets
Write me a for loop if you are walking in a square
for i in 1 ... 4 {
moveForward()
turnRight()
}
Locate the bug:
for i in 1 ... 16 {
if isongem {
collectGem()
turnLeft()
} else {
moveForward()
}
isOnGem
Write this pseudocode in Swift: "If there is an open switch, and I am blocked, I will close the switch and turn right, else I will collect the gem and turn around 180 degrees."
if isOnOpenSwitch && isBlocked {
toggleSwitch()
turnRight()
} else {
collectGem()
turnLeft()
turnLeft()
}
Write me a loop for this scenario: "While the conveyor bely is on, I will put grocery items on belt"
putItemOnBelt()
}