Font size
WorksheetsSwift Programming Quiz
Total questions: 11
Worksheet time: 22mins
What is a variable used for in Swift?
To draw shapes
To store data or values
To stop a loop
To print text
Which line of code correctly creates a variable in Swift?
var name = "Alex"
let name = Alex
variable name = "Alex"
make name = "Alex"
What does this code do?
for i in 1...3
{ moveForward() }
Moves forward once
Moves forward 3 times
Moves forward 4 times
Doesn’t move at all
What is 'i' called in a for loop like this one?
for i in 1...5
{
print(i)
}
A variable that counts the loop number
A string
A conditional
A function
Which keyword starts a conditional statement in Swift?
repeat
if
for
What will this code print? let gems = 5 if gems > 3
{ print("You win!") }
else
{ print("Try again.") }
You win!
Try again.
Error
Nothing
Which are logical operators in Swift?
and, or, not
+, -, *, /
&&, ||, !
if, else, repeat
What will this code print? let isDoorOpen = false let hasKey = true if isDoorOpen || hasKey
{ print("You can enter!") }
else
{ print("Door locked.") }
You can enter!
Door locked.
Error
Nothing
Fill in the blank: In Swift, an if statement helps your code make (a) .
What will this code print? var score = 5 score = score + 3 print(score)
5
3
8
Error
Which condition will result true?
let hasGem = true let isOnSwitch = false
hasGem && isOnSwitch
hasGem || isOnSwitch
!hasGem
isOnSwitch && hasGem
