wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Swift Programming Quiz

Total questions: 11

Worksheet time: 22mins

Name
Class
Date
1.

What is a variable used for in Swift?

a)

To draw shapes

b)

To store data or values

c)

To stop a loop

d)

To print text

2.

Which line of code correctly creates a variable in Swift?

a)

var name = "Alex"

b)

let name = Alex

c)

variable name = "Alex"

d)

make name = "Alex"

3.

What does this code do?

for i in 1...3

{ moveForward() }

a)

Moves forward once

b)

Moves forward 3 times

c)

Moves forward 4 times

d)

Doesn’t move at all

4.

What is 'i' called in a for loop like this one?

for i in 1...5

{

print(i)

}

a)

A variable that counts the loop number

b)

A string

c)

A conditional

d)

A function

5.

Which keyword starts a conditional statement in Swift?

a)

repeat

b)

if

c)

for

d)

print

6.

What will this code print? let gems = 5 if gems > 3

{ print("You win!") }

else

{ print("Try again.") }

a)

You win!

b)

Try again.

c)

Error

d)

Nothing

7.

Which are logical operators in Swift?

a)

and, or, not

b)

+, -, *, /

c)

&&, ||, !

d)

if, else, repeat

8.

What will this code print? let isDoorOpen = false let hasKey = true if isDoorOpen || hasKey

{ print("You can enter!") }

else

{ print("Door locked.") }

a)

You can enter!

b)

Door locked.

c)

Error

d)

Nothing

9.

Fill in the blank: In Swift, an if statement helps your code make (a)   .

10.

What will this code print? var score = 5 score = score + 3 print(score)

a)

5

b)

3

c)

8

d)

Error

11.

Which condition will result true?

let hasGem = true let isOnSwitch = false

a)

hasGem && isOnSwitch

b)

hasGem || isOnSwitch

c)

!hasGem

d)

isOnSwitch && hasGem