WorksheetsAP CSP Loops Practice
Total questions: 12
Worksheet time: 11mins
Which word means the same as "repeat".
Iterate
program
loop
for loop
Is used to repeat a specific block of code an unknown number of times, until a condition is met.
Iteration
Infinite Loop
For Loop
While Loop
Is used to repeat a specific block of code a known number of times.
Iteration
Infinite Loop
For Loop
While Loop
Read each scenario. In which would a loop be most helpful?
Maura wants a program to perform a math operation one time.
Jamila is programming a robot to hop once and then raise its arm once.
Vinny wants a program to go through a list of 35 of his friends and remind each friend what time a study group starts.
Damian is writing a program that will tell him what to wear depending on the weather.
adds one to variable x in a loop
increment (x)
x++;
x=x;
y+1;
How many times will the following program print "hello"?
10
11
9
This code will loop infinitely
What is wrong with this loop?
Nothing, it works
moveForward is not a command
The value of the variable is 0
It never ends
We want to simulate constantly flipping a coin until we get 3 heads in a row. What kind of loop should we use?
For loop
While loop
Loop and a half
Infinite loop
OUTPUT?
var i = 1;
while (i < 5) {
System.out.println("Hello");
i++;
}
Hello
Hello
Hello
Hello
Hello
Hello
Hello
Hello
Hello
Hello
Hello
Hello
Hello
What is the final sum after this loop executes
sum = 5
sum = 10
sum = 15
What are the values of count1 and count2 as a result of executing the code segment?
count1 = 2, count2 = 2
count1 = 2, count2 = 3
count1 = 3, count2 = 2
count1 = 5, count2 = 0
What will be displayed in the console when the following program runs?
0 2 4 6
0 2 4
2 4 6
The program will result in an infinite loop
