wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Programming Loops Quiz

Total questions: 25

Worksheet time: 13mins

Name
Class
Date
1.

What is the main purpose of loops in programming?

a)

To make code longer

b)

To automate repetitive tasks

c)

To create errors

d)

To slow down programs

2.

What will this code print?

a)

1, 2, 3, 4, 5

b)

0, 1, 2, 3, 4

c)

0, 1, 2, 3, 4, 5

d)

1, 2, 3, 4

3.

What is the key difference between for loops and while loops?

a)

For loops are faster

b)

For loops repeat N times (known iterations), while loops repeat until condition is False (unknown iterations)

c)

While loops are better

d)

There is no difference

4.

What does range(1, 6) generate?

a)

1, 2, 3, 4, 5, 6

b)

0, 1, 2, 3, 4, 5

c)

1, 2, 3, 4, 5

d)

2, 3, 4, 5, 6

5.

What will range(0, 11, 2) generate?

a)

0, 2, 4, 6, 8, 10

b)

0, 2, 4, 6, 8, 10, 12

c)

2, 4, 6, 8, 10

d)

1, 3, 5, 7, 9, 11

6.

What does the third parameter in range(start, stop, step) represent?

a)

The starting number

b)

The stopping number

c)

The increment/step value

d)

The number of iterations

7.

What will this code print?

a)

5, 4, 3, 2, 1

b)

0, 1, 2, 3, 4, 5

c)

5, 4, 3, 2, 1, 0

d)

1, 2, 3, 4, 5

8.

What is the most critical thing to remember when writing while loops?

a)

Use proper indentation

b)

Always update the condition variable to avoid infinite loops

c)

Use print statements

d)

Start from 0

9.

What will this code print?

a)

1, 2, 3

b)

1, 2, 3, 4

c)

0, 1, 2, 3

d)

Infinite loop

10.

What happens if you forget to update the condition variable in a while loop?

a)

The program runs faster

b)

The loop creates an infinite loop

c)

The loop runs once

d)

Nothing happens

11.

What does the 'break' statement do?

a)

Skips the current iteration

b)

Exits the loop completely

c)

Pauses the loop

d)

Restarts the loop

12.

What does the 'continue' statement do?

a)

Exits the loop completely

b)

Skips the current iteration and moves to the next one

c)

Continues to the next line

d)

Does nothing

13.

What will this code print?

a)

1, 2, 3, 4, 5

b)

1, 2

c)

1, 2, 3

d)

4, 5

14.

What will this code print?

a)

1, 2, 3, 4, 5

b)

1, 2, 4, 5

c)

3

d)

1, 2

15.

What is the output of this code?

a)

3

b)

6

c)

10

d)

4

16.

In Python, does range() include the stop value?

a)

Yes, always

b)

No, it stops BEFORE the stop value

c)

Sometimes

d)

Only with negative step

17.

What will this code print?

a)

All numbers 1-10

b)

Only odd numbers: 1, 3, 5, 7, 9

c)

Only even numbers: 2, 4, 6, 8, 10

d)

Nothing

18.

Which loop structure is best when you know exactly how many times to repeat?

a)

while loop

b)

for loop

c)

Both are equally good

d)

Neither

19.

Which loop structure is best for input validation (keep asking until valid)?

a)

for loop

b)

while loop

c)

if statement

d)

elif statement

20.

What will this code do?

a)

Run forever with no way to stop

b)

Run until user types "quit"

c)

Run once

d)

Cause an error

21.

What is the result of range(5)?

a)

1, 2, 3, 4, 5

b)

0, 1, 2, 3, 4

c)

0, 1, 2, 3, 4, 5

d)

5

22.

How do you create a countdown from 10 to 1 using range()?

a)

range(10, 1)

b)

range(10, 0, -1)

c)

range(1, 10)

d)

range(10, 1, -1)

23.

What is wrong with this code?

a)

Missing increment (count should be updated)

b)

Wrong condition

c)

Missing colon

d)

Nothing is wrong

24.

What will this code print?

a)

Python (once)

b)

Python (twice)

c)

Python (three times)

d)

0, 1, 2

25.

In a password retry system with 3 attempts, which loop is most appropriate?

a)

for loop with range(3)

b)

while loop with attempt counter

c)

Either could work

d)

No loop needed