You can start a loop at whatever you want. The reason you see loops starting at zero often, is because they are looping through an array. Since the first item in an array is at index '0', it makes sense to start looping from 0 to access every item in an array.

Answer from Aksel on Stack Exchange
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_for_loops.asp
Python For Loops
To loop through a set of code a specified number of times, we can use the range() function, The range() function returns a sequence of numbers, starting from 0 by default, and increments by 1 (by default), and ends at a specified number.
Top answer
1 of 3
10

You can start a loop at whatever you want. The reason you see loops starting at zero often, is because they are looping through an array. Since the first item in an array is at index '0', it makes sense to start looping from 0 to access every item in an array.

2 of 3
2

You should use i = 0 in situations where iterating starting at zero would be natural, as previously stated this could include array indexing or similar. Personally I would say I use this style at least 90% of the time, as when modelling problems in the computer we mold them to use built in data structures, which usually start at 0. Our minds become use to working in this style.

Starting at i = 1 is more natural for modeling many problems while designing algorithms. For example, if you are given a problem such as person 1 is x years old, person 2 is y years old, and so on, indexing using the given numbers may make it easier to give an answer if asked something such as who is the youngest person in the list. Experience and experimentation will teach you if this is worthwhile, in my experience, this can be helpful in things such as programming competitions (like the ICPC), where algorithms must be developed quickly with not much time for debugging, and the algorithms can be very complex, so the clarity is important.

In other words it may be beneficial to waste this first index if it adds clarity, however experienced programmers quickly learn to understand both styles.

However, if you start at zero, remember to be aware that the arrays still start at zero, and you will need an n + 1 size array to represent n elements if you use indexing starting at 1.

Also be aware of your conditional in the for loop.

for (int i = 0; i < 10; i++) - Will loop 10 times

for (int i = 1; i <= 10; i++) - Will loop 10 times

It is basic, but a common source of errors that may be hard to track down, especially for beginning programmers.

๐ŸŒ
Quora
quora.com โ€บ Do-for-and-while-loops-begin-at-0-or-1
Do for and while loops begin at 0 or 1? - Quora
Answer (1 of 17): In most modern languages - they do what you tell them to do. [code]for ( i = 0 ; i
Find elsewhere
๐ŸŒ
Python
wiki.python.org โ€บ moin โ€บ ForLoop
ForLoop - Python Wiki
for x in range(0, 3): print("We're on time %d" % (x)) While loop from 1 to infinity, therefore running forever. x = 1 while True: print("To infinity and beyond! We're getting close, on %d now!" % (x)) x += 1 ยท When running the above example, you can stop the program by pressing ctrl+c at the same time.
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ python-for-loop-example
Python for loop | DigitalOcean
March 14, 2024 - Here, 100 is the start value, 0 is the stop value, and -10 is the range, so the loop begins at 100 and ends at 0, decreasing by 10 with each iteration. This occurs in the output: ... When programming in Python, for loops often make use of the range() sequence type as its parameters for iteration.
๐ŸŒ
Codecademy
codecademy.com โ€บ forum_questions โ€บ 4f52839209a70f0003014446
2.4: Why does the loop start at 0 and not 1? | Codecademy
getFizzBuzzSum: function(number) ... both . . . }, ... Fair enough. Do you still have to start at zero? ... Yes, because you want to loop 100 times. That is, 0 through 99....
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ python โ€บ how to start python for loop at 1
How to Start Python For Loop at 1 - Spark By {Examples}
May 31, 2024 - To start a Python for loop at 1 instead of 0, you can use the range function and specify a starting value of 1. For example, range(1,6) generates a sequence of numbers starting from 1 and going up to, but not including, 6.
๐ŸŒ
Python Course
python-course.eu โ€บ python3_for_loop.php
20. For Loops | Python Tutorial | python-course.eu
August 16, 2021 - An example of this kind of loop is the for-loop of the programming language C: for (i=0; i <= n; i++) This kind of for loop is not implemented in Python! ... This kind of for loop is a simplification of the previous kind. It's a counting or enumerating loop. Starting with a start value and counting up to an end value, like for i = 1 to 100 Python doesn't use this either.
๐ŸŒ
Berkeley
pythonnumericalmethods.studentorg.berkeley.edu โ€บ notebooks โ€บ chapter05.01-For-Loops.html
For-Loops โ€” Python Numerical Methods
First, the function range(1, 4) ... a very simple form, it is range(start, stop, step), and the step is optional with 1 as the default. The variable n is assigned the value 0....
๐ŸŒ
Quora
quora.com โ€บ Why-do-you-use-I-0-in-while-loops
Why do you use I=0 in while loops? - Quora
... Both loops iterate ten times - the first one counts from 0 to 9 (inclusively) - the second goes from 1 to 10 (inclusively). Most programmers will start from zero - somewhat from habit and somewhat because one so often wants to use the loop ...
๐ŸŒ
Real Python
realpython.com โ€บ python-for-loop
Python for Loops: The Pythonic Way โ€“ Real Python
February 23, 2026 - In this example, instead of using enumerate() to produce zero-based indices, you start the count at 1. From the end userโ€™s perspective, starting the menu at 1 is the natural way to go. Looping through two or more iterables in parallel may be another common task you encounter in Python programming. To do this, you can use the built-in zip() function, which takes two or more iterables and yields tuples that combine items from each iterable.