wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

AP CSP Loops Practice

Total questions: 12

Worksheet time: 11mins

Name
Class
Date
1.

Which word means the same as "repeat".

a)

Iterate

b)

program

c)

loop

d)

for loop

2.

Is used to repeat a specific block of code an unknown number of times, until a condition is met.

a)

Iteration

b)

Infinite Loop

c)

For Loop

d)

While Loop

3.

Is used to repeat a specific block of code a known number of times.

a)

Iteration

b)

Infinite Loop

c)

For Loop

d)

While Loop

4.

Read each scenario. In which would a loop be most helpful?

a)

Maura wants a program to perform a math operation one time.

b)

Jamila is programming a robot to hop once and then raise its arm once.

c)

Vinny wants a program to go through a list of 35 of his friends and remind each friend what time a study group starts.

d)

Damian is writing a program that will tell him what to wear depending on the weather.

5.

adds one to variable x in a loop

a)

increment (x)

b)

x++;

c)

x=x;

d)

y+1;

6.

How many times will the following program print "hello"?

a)

10

b)

11

c)

9

d)

This code will loop infinitely

7.

What is wrong with this loop?

a)

Nothing, it works

b)

moveForward is not a command

c)

The value of the variable is 0

d)

It never ends

8.

We want to simulate constantly flipping a coin until we get 3 heads in a row. What kind of loop should we use?

a)

For loop

b)

While loop

c)

Loop and a half

d)

Infinite loop

9.

OUTPUT?

var i = 1;

while (i < 5) {

System.out.println("Hello");

i++;

}

a)

Hello

Hello

Hello

Hello

Hello

b)

Hello

Hello

Hello

Hello

c)

Hello

Hello

Hello

d)

Hello

10.

What is the final sum after this loop executes

a)

sum = 5

b)

sum = 10

c)

sum = 15

11.

What are the values of count1 and count2 as a result of executing the code segment?

a)

count1 = 2, count2 = 2

b)

count1 = 2, count2 = 3

c)

count1 = 3, count2 = 2

d)

count1 = 5, count2 = 0

12.

What will be displayed in the console when the following program runs?

a)

0 2 4 6

b)

0 2 4

c)

2 4 6

d)

The program will result in an infinite loop