RG's E-Learning Centre · Book a free demo class · WhatsApp +91-9379416374

Counting loop iterations: Class 11 practice

range(a, b, s) produces a, a + s, … stopping before b. The quick answer and an example come first; then the method, worked examples and six graded questions.

Counting loop iterations: quick answer

range(a, b, s) produces a, a + s, … stopping before b. Nested loops multiply: an outer loop of m and an inner loop of n run the body m × n times.

Example: How many times does the body of for i in range(0, 12, 2): run? Answer: 6.

  • Where it is taught: "Flow of Control", Class 11 Computer Science.
  • On this page: the method, 3 worked examples and 6 graded questions with a full answer key.

How to use this page (about 30 minutes)

  1. Read the method once, then cover the worked examples and try them yourself before reading the steps.
  2. Do the two Basic questions without notes. If either is wrong, re-read the matching worked example.
  3. Do the Standard and Challenge questions, then check every line of working against the answer key — not only the final answer.
  4. Write down the mistake behind each wrong answer and redo that question the next day.

What you should know first

  • range()

The idea behind counting loop iterations

range(a, b, s) produces a, a + s, … stopping before b. Nested loops multiply: an outer loop of m and an inner loop of n run the body m × n times.

Step-by-step method

  1. Find the values produced by each range.
  2. Count them: ⌈(b − a)/s⌉ when positive.
  3. Multiply for nested loops (or add a triangular count when the inner depends on the outer).

Worked example 1 (Basic)

How many times does the body of for i in range(0, 12, 2): run?

  1. Values 0, 2, … < 12
  2. Count = 6
  3. Answer: 6

Worked example 2 (Standard)

for i in range(7): for j in range(6): count += 1. What is count?

  1. 7 × 6
  2. Answer: 42

Worked example 3 (Challenge)

for i in range(8): for j in range(i): count += 1. What is count?

  1. 0 + 1 + … + 7
  2. = 28
  3. Answer: 28

Common mistakes and misconceptions

  • Including the stop value
  • Adding instead of multiplying nested counts

Practice questions

  1. (Basic) How many times does the body of for i in range(1, 16, 2): run?
  2. (Basic) How many times does the body of for i in range(0, 11, 1): run?
  3. (Standard) for i in range(3): for j in range(4): count += 1. What is count?
  4. (Standard) for i in range(5): for j in range(8): count += 1. What is count?
  5. (Challenge) for i in range(12): for j in range(i): count += 1. What is count?
  6. (Challenge) for i in range(6): for j in range(i): count += 1. What is count?

Answer key with full working

  • Q1: Values 1, 3, … < 16 → Count = 8 → Answer: 8
  • Q2: Values 0, 1, … < 11 → Count = 11 → Answer: 11
  • Q3: 3 × 4 → Answer: 12
  • Q4: 5 × 8 → Answer: 40
  • Q5: 0 + 1 + … + 11 → = 66 → Answer: 66
  • Q6: 0 + 1 + … + 5 → = 15 → Answer: 15

Which textbook this practice follows

This skill is taught under "Flow of Control" in Class 11 Computer Science. Check your own textbook's contents page — CBSE, ICSE/ISC and state boards order chapters differently.

Answers on this page are generated and automatically re-checked by a second, independent calculation. They have not been reviewed by a teacher — if you spot a problem, tell us on WhatsApp.

Still stuck after the answer key?

If the same step in counting loop iterations keeps going wrong, a short live 1 on 1 class can find the exact gap. The first demo class is free; send the class, board and chapter on WhatsApp (+91 9379416374).

Related practice and notes

More Class 11 Computer Science practice

Continue with this syllabus

Frequently asked questions

Which chapter is counting loop iterations in?

This skill is taught under "Flow of Control" in Class 11 Computer Science. Check your own textbook's contents page — CBSE, ICSE/ISC and state boards order chapters differently.

Which question should I start with?

Start with the Basic questions. Move to Standard only when both Basic answers match the key with the same working; the Challenge questions combine this skill with earlier ones.

How were the answers checked?

Answers on this page are generated and automatically re-checked by a second, independent calculation. They have not been reviewed by a teacher — if you spot a problem, tell us on WhatsApp.

Is this only for CBSE?

The skill names follow NCERT/CBSE, but the method is the same for ICSE, state boards, IGCSE and IB. Only the chapter name and order differ.

Can I get live help with this topic?

Yes. RG's E-Learning teaches live 1 on 1 online classes; the first demo class is free and fees are shared after it.

Book a free demo class