Algorithms & Concepts
Loops
Break & Continue
Bug & Debugging
Nested Loops
100

What is an algorithm?

A step-by-step procedure to solve a problem.

100

What is a loop?

A loop repeats a block of code.

100

What does break do?

It stops the loop completely.

100

What is a bug?

An error or unexpected problem in a program.Q: What is a nested loop?

100

What is a nested loop?

A loop inside another loop.

200

What are the three basic programming structures?

Sequence, Selection and Iteration.

200

Name three types of loops.

While loop, For loop and Nested loop.

200

What does continue do?

It skips the current iteration and moves to the next one.

200

What is debugging?

The process of finding and fixing bugs in a program.

200

Which loop is placed inside another loop?

Inner loop.

300

What is selection?

Making a choice based on a condition using if/else.

300

What is a while loop?

A loop that executes while a condition is true.

300

What is the difference between break and continue?

break stops the entire loop; continue skips the current iteration.

300

What is the purpose of debugging?

To find and fix errors/bugs in a program.

300

If the outer loop runs 2 times and the inner loop runs 3 times, how many times does the inner statement execute?

6 times.

400

What is iteration?

Repeating a task or set of instructions.

400

What does range(0,6) produce?

0,1,2,3,4,5

400

When would you use continue instead of break?

When you want to skip one iteration but continue the loop.

400

Find the bug:
for i in range(1,-5):

range(1,-5) is the bug

400

How many stars are printed?
for i in range(1,4):
    for j in range(1,5):
        print("*")

12 stars.

500

A program needs to: check whether it is raining, repeat taking attendance for 5 students, and then display “Attendance Complete”. Which three structures are being used, where and why?

Selection for checking rain, Iteration for repeating attendance 5 times, and Sequence because the instructions happen in order.

500

Without running the code, explain how many times Hello is printed:
for i in range(2,8):
    print("Hello")

6 times — range(2,8) gives 2, 3, 4, 5, 6, 7.

500

What will happen when i becomes 3?
for i in range(1,7):
    if i == 3:
        continue
    if i == 5:
        break
    print(i)

It prints 1, 2, 4. 3 is skipped and when i = 5, the loop stops.

500

Find and explain the bug:
i = 1
while i <= 5:
    print(i)

i is never increased, so the condition always remains true. Add i = i + 1 inside the loop.

500

You want a sprite to draw a 3 × 3 square of dots using nested loops. The outer loop controls the rows, and the inner loop controls the dots in each row.

How many times should each loop repeat?  

  • Outer loop → 3 times (3 rows)
  • Inner loop → 3 times (3 dots in each row)
  • Total dots → 9
M
e
n
u