KwickAcademy Python · 8 min · free
for Loop and range()
Learn the Python for loop and range(): iteration, range(start, stop, step), strings, lists, accumulators and exam programs. Iteration means repeating the same steps; a loop is the part of a program that repeats.
Follows the syllabus of: CBSE Class 11 Computer Science (083)
On screen in this lesson
What is iteration?
| Iteration: repeating the same steps |
| Loop: code that repeats |
| Each repeat is one iteration |
| Less code and fewer typing mistakes |
Watch the counter move
| Iteration | count | Printed |
|---|---|---|
| 1st | 0 | 0 |
| 2nd | 1 | 1 |
| 3rd | 2 | 2 |
| 4th | 3 | 3 |
| 5th | 4 | 4 |
Rules for writing a for loop
| for, a variable, in, a sequence, then a colon |
| Indent the body, usually by 4 spaces |
| No colon gives SyntaxError |
| No indent gives IndentationError |
Pause and predict
| Call | Gives |
|---|---|
| range(4) | 0 1 2 3 |
| range(3, 7) | 3 4 5 6 |
| range(1, 10, 3) | 1 4 7 |
| range(10, 4, -2) | 10 8 6 |
| range(5, 5) | nothing |
Quick recap
| Iteration: repeating steps; a loop does it |
| range(stop) starts at 0 and stops before stop |
| range(start, stop, step): step is the jump |
| for can go over strings and lists |
| Accumulator: set before, update inside, print after |
Quick answers
Does range(5) give 1 to 5?
No, it gives 0 to 4. Stop is never included.
Why does factorial start at 1, not 0?
Starting at 0 would make every product 0.
KwickClips from this lesson
Short clips, one idea each. Good for revision the night before.
What is iteration?43 sec
Is stop included?43 sec
What does a string give in a for loop?37 sec
Where do you set the accumulator?41 sec
Why does factorial start at 1?43 secThe full lesson, in text
Aarav, my little brother's maths homework is the table of seven. So we wrote a loop to check his answers.
Achha, better than typing ten print lines. So what went wrong?
It stops at sixty three! Where did seventy go? My code clearly says one to ten.
If he copies this, seven into ten goes missing, and his teacher will cut marks!
Hmm, range does something odd with the last number. My exam is tomorrow, so let's not guess. Come, let's ask Kajal Ma'am.
Good question, Riya. Your range of one comma ten stops at nine, and today you will see exactly why. We learn the for loop, the range function, and three programs exams ask again and again.
First, a new word. Iteration means repeating the same steps. A loop is code that does this repeating. Each single repeat is one iteration. With a loop, a hundred print lines become two, with fewer typing mistakes.
We write for, a variable called count, in, range of five, and a colon. The next line is indented, pushed right by four spaces. That indented body repeats. Python prints zero, one, two, three and four.
But range of five should print five too, na?
No, Riya. Range of five gives five numbers starting at zero, so the last one is four.
Let us watch the counter move. In the first iteration, count is zero. In the second, count is one. In the third, count is two. In the fourth, count is three. In the fifth, count is four, then no values are left, so the loop ends.
Here is the same loop as a flowchart. First, Python gets the values from range of five. The diamond asks, is any value left? If yes, count takes the next value, prints it, and goes back. If no, the flow leaves the loop.
Remember four rules. Write for, a variable, in, a sequence, and a colon. Indent the body, usually by four spaces. Forget the colon, and Python gives a syntax error. Forget the indent, and it gives an indentation error.
With one value, called stop, range starts at zero and stops just before stop. Here print has end equals a space, so the numbers stay on one line. Memory hook: range stops before the stop.
With two values, start is included, but stop is never included. For one to ten, we write range of one comma eleven. Exam tip: to reach a number, stop is always that number plus one.
Oh! So my range of one comma ten stopped at nine.
Exactly. That is why your table stopped at sixty three.
The third value is step, the jump between numbers. Range of two comma eleven comma two starts at two, jumps by two, and stops before eleven. So we get the even numbers up to ten.
A negative step counts backwards, like a rocket countdown. Range of five comma zero comma minus one goes down by one. It prints five, four, three, two and one.
So range of five comma zero comma minus one also prints zero?
No, Aarav. Stop is never included, even counting down, so it ends at one.
Pause the video and predict each answer. Range of four gives zero to three. Range of three comma seven gives three to six. Range of one comma ten comma three gives one, four, seven. Range of ten comma four comma minus two gives ten, eight, six. Range of five comma five gives nothing, because start equals stop.
A for loop can also go over a string, which is text inside quotes. It takes one letter at a time from Delhi. Notice the dash after the last letter too.
A list is many values inside square brackets, separated by commas. The loop takes one snack at a time, so the body runs three times. No range is needed here.
Now the accumulator, a variable that collects a result bit by bit. These are runs from five balls. Total starts at zero before the loop. Inside, total becomes total plus run. After the loop, we print it once. Four, six, zero, one and six make seventeen. Memory hook: set before, update inside, print after.
A counter is an accumulator that adds one each time. The if line asks, is mark greater than or equal to thirty three? Only then does passed go up by one. Seventy two, forty five and ninety pass, so it prints Passed, three.
Now three exam programs. First, the table of seven. The star sign means multiply. Times goes from one to ten, so we write range of one comma eleven. Each time, Python prints num into times, followed by a space. We get seven, fourteen, and so on, up to seventy.
Second, the factorial of five, five into four into three into two into one, which is one hundred twenty. The loop multiplies fact by each value from one to num. Exam tip: a product starts at one, a sum starts at zero. Pause and predict: what if num is zero? The loop never runs, so it prints one, and zero factorial is one.
Can fact start at zero, like total did?
No. Zero into anything is zero, so fact must start at one.
Third, the sum of the series one plus three plus five, up to nineteen. These are odd numbers, so range starts at one with a step of two. Stop is twenty, so nineteen is the last value. The total is one hundred. Exams change the series, but the pattern stays the same.
Seventy is here! Stop is never included, so for one to ten, it is range of one comma eleven.
Check the last line properly. Is seven into ten there now?
Yes, seventy is the last number. Nothing is missing.
Two lines instead of ten. That is a six off the last ball, yaar!
And if he needs the table up to twenty, just range of one comma twenty one?
Same two lines. Your brother will think you are a genius.
Achha, now show me your exam doubts. My turn to help.
Only if you explain it as calmly as Kajal Ma'am did, okay?
Let us revise. Iteration means repeating steps, and a loop does it. Range of stop starts at zero and stops just before stop. With start, stop and step, the step is the jump, and a negative step counts down. A for loop can also go over strings and lists. An accumulator is set before the loop, updated inside, and printed after.
Courses that teach this
| Course | Unit |
|---|---|
| CBSE Class 11 Computer Science (083) | Computational Thinking and Programming - I |
| CBSE Class 11 Computer Science Essentials (083) | Computational Thinking and Programming - I |
| CBSE Class 11 Informatics Practices (065) | Introduction to Python |
| Programming All levels Python | Control Flow |
Voice-over in this lesson is AI-generated. The script is written and checked by Kajal Ma'am. Boards can revise a syllabus mid-year, so confirm anything you plan around against the official board circular. Keep your passwords, OTPs and ID numbers to yourself — we never ask for them. To reach Kajal Ma'am, use the WhatsApp button; sharing your number there is how we call you back.
Free to watch, no sign-up. Live classes with Kajal Ma'am are the paid course; these lessons stay free either way.

