Class 7 · CBSE AI · Strand B — Python for AI

Python loops and conditionals explained for Class 7

How for-loops repeat work and if-statements make choices in Python — including why indentation matters. For Class 7.

What this concept actually says

  • A for loop repeats an action for every item in a collection without you writing the action multiple times
  • An if/elif/else conditional runs different code depending on whether a condition is true or false
  • Combining loops and conditionals is how almost all real data processing logic is built

An analogy your child will recognise

Chai making

Making one cup of chai is a set of steps. Making chai for a family of five is a loop — you repeat the same steps for each cup. A conditional is like checking the sugar preference: 'if they want it sweet, add two spoons; else, add none.'

Ticket checker on a train

A ticket checker walks through every compartment (the loop) and for each passenger checks: 'Do they have a valid ticket?' (the conditional). Depending on the answer, they either move on or ask the passenger to pay. Every real job involves this loop-and-check pattern.

Common misconceptions to watch for

  • elif and else are mandatory after an if — in reality, if can stand alone when no alternative action is needed
  • Indentation is just for readability — in reality, incorrect indentation in Python is a syntax error that stops the program from running

Key facts in one breath

  • Python uses indentation (spaces) to define what is inside a loop or conditional — there are no curly braces
  • The range() function generates a sequence of numbers, commonly used with for loops
  • An infinite while loop (one that never terminates) is one of the most common beginner bugs
  • The break statement exits a loop early; the continue statement skips to the next iteration

How Dhee Learning teaches this — the 3-stage question loop

Every Dhee Learning session for this concept follows three stages. We share the questions Dhee actually asks, so you can hear what a session sounds like.

Stage 1 — Surface

You have a list of 100 exam scores and want to print only the ones above 90. How many lines of code would that take if you had no loop?

Rote answer

"A for loop repeats code"

Understood

"Without a loop you would write the same check 100 times and the code would break the moment you had 101 scores — a loop lets you write the logic once and apply it to every item automatically"

Stage 2 — Reasoning

What is the difference between a for loop and a while loop? Can you think of a situation where you would prefer a while loop over a for loop?

Follow-up Dhee may use: What is the risk of a while loop that a for loop does not have? What could go wrong?

Stage 3 — Application

Given a list of ten student scores, write code that prints 'Distinction' for scores above 75, 'Pass' for scores between 40 and 75, and 'Needs Support' for below 40. Walk me through your logic before you code it.

Misconception Dhee watches for: Writing if score > 75 and if score > 40 as two separate ifs instead of elif, which causes scores above 75 to also trigger the second condition

Related concepts

Want your child to actually understand this?

Dhee turns this concept into a 15-minute spoken session — asking, listening, and probing — so your child builds the idea themselves.

Frequently asked questions

What is loops and conditionals — explained for kids? +

How for-loops repeat work and if-statements make choices in Python — including why indentation matters. For Class 7.

What's the most common mistake children make about this concept? +

elif and else are mandatory after an if — in reality, if can stand alone when no alternative action is needed

How does Dhee Learning teach this in a Class 7 session? +

Dhee opens with a question — for example: "You have a list of 100 exam scores and want to print only the ones above 90. How many lines of code would that take if you had no loop?" — listens to your child's answer, then probes the reasoning behind it. The session ends when the child can apply the idea to a brand-new situation, not just recall it.