Python's for loops are different. i gets reassigned to the next value every time through the loop.

The following will do what you want, because it is taking the literal version of what C++ is doing:

i = 0
while i < some_value:
    if cond...:
        i+=1
    ...code...
    i+=1

Here's why:

in C++, the following code segments are equivalent:

for(..a..; ..b..; ..c..) {
    ...code...
}

and

..a..
while(..b..) {
     ..code..
     ..c..
}

whereas the python for loop looks something like:

for x in ..a..:
    ..code..

turns into

my_iter = iter(..a..)
while (my_iter is not empty):
    x = my_iter.next()
    ..code..
Answer from jakebman on Stack Overflow
๐ŸŒ
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 ...
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_for_loops.asp
Python For Loops
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string).
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-for-loops
Python For Loops - GeeksforGeeks
Python continue Statement returns the control to the beginning of the loop. ... # Prints all letters except 'e' and 's' for i in 'geeksforgeeks': if i == 'e' or i == 's': continue print(i)
Published ย  3 weeks ago
๐ŸŒ
Learn Python
learnpython.org โ€บ en โ€บ Loops
Loops - Learn Python - Free Interactive Python Tutorial
# Prints out 0,1,2,3,4 count = 0 while True: print(count) count += 1 if count >= 5: break # Prints out only odd numbers - 1,3,5,7,9 for x in range(10): # Check if x is even if x % 2 == 0: continue print(x) Unlike languages like C,CPP.. we can use else for loops. When the loop condition of "for" or "while" statement fails then code part in "else" is executed. If a break statement is executed inside the for loop then the "else" part is skipped. Note that the "else" part is executed even if there is a continue statement.
๐ŸŒ
Real Python
realpython.com โ€บ python-for-loop
Python for Loops: The Pythonic Way โ€“ Real Python
February 23, 2026 - Jane 25 Python Dev Canada >>> text = "abcde" >>> for character in text: ... print(character) ... a b c d e >>> for index in range(5): ... print(index) ... 0 1 2 3 4 ยท In these examples, you iterate over a tuple, string, and numeric range. Again, the loop traverses the sequence in the order of definition.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ loops-in-python
Loops in Python - GeeksforGeeks
It allow to execute a block of code repeatedly, once for each item in the sequence. ... Explanation: This code prints the numbers from 0 to 3 (inclusive) using a for loop that iterates over a range from 0 to n-1 (where n = 4).
Published ย  1 week ago
๐ŸŒ
Python Course
python-course.eu โ€บ python-tutorial โ€บ for-loops.php
20. For Loops | Python Tutorial | python-course.eu
Generally it has the form: for (A; Z; I) A is the initialisation part, Z determines a termination expression and I is the counting expression, where the loop variable is incremented or dcremented. An example of this kind of loop is the for-loop of the programming language C: for (i=0; i <= n; ...
Find elsewhere
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ for-loop
Python for Loop (With Examples)
If we don't intend to use items of sequence inside the body of a loop, it is clearer to use the _ (underscore) as the loop variable. For example, # iterate from i = 0 to 3 for _ in range(0, 4): print('Hi')
๐ŸŒ
Berkeley
pythonnumericalmethods.studentorg.berkeley.edu โ€บ notebooks โ€บ chapter05.01-For-Loops.html
For-Loops โ€” Python Numerical Methods
s = 0 a = [2, 3, 1, 3, 3] for i in a: s += i # note this is equivalent to s = s + i print(s) ... The Python function sum has already been written to handle the previous example. However, assume you wish to add only the even numbers. What would you change to the previous for-loop block to handle ...
๐ŸŒ
Python.org
discuss.python.org โ€บ ideas
"for i in range()" to do an infinite loop with a counter - Ideas - Discussions on Python.org
August 10, 2022 - Hi, Usually in Python we can avoid the i = 0 โ€ฆ i += 1 paradigm that we use in other languages when we need to count things, thanks to enumerate(...), for i in range(100), etc. Along the years I have nearly always found a more โ€œpythonicโ€ replacement for code containing i = 0 โ€ฆ i += 1. There is an exception with this code: an infinite loop with a counter: i = 0 while True: ... if breaking_condition: break i += 1 Proposal: could we accept that range() without any parameter ...
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ python-for-loop-for-i-in-range-example
Python For Loop - For i in Range Example
March 30, 2021 - # Example with two arguments for i in range(-1, 5): print(i, end=", ") # prints: -1, 0, 1, 2, 3, 4, The optional step value controls the increment between the values in the range. By default, step = 1. In our final example, we use the range of integers from -1 to 5 and set step = 2. # Example with three arguments for i in range(-1, 5, 2): print(i, end=", ") # prints: -1, 1, 3, In this article, we looked at for loops in Python and the range() function.
๐ŸŒ
Data Science Discovery
discovery.cs.illinois.edu โ€บ learn โ€บ Simulation-and-Distributions โ€บ For-Loops-in-Python
For-Loops in Python - Data Science Discovery
A simple and widely used application is to re-run a simulation multiple times and these for-loops nearly always use for i in range(17) (where 17 is replaced with the number of times our simulation runs). range(17) is shorthand for listing out a long sequence of numbers starting with zero and going to one less than the end of the range -- [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16] -- that will be "looped through" by the for-loop.
๐ŸŒ
Snakify
snakify.org โ€บ for loop with range
For loop with range - Learn Python 3 - Snakify
result = 0 n = 5 for i in range(1, n + 1): result += i # this ^^ is the shorthand for # result = result + i print(result) Pay attention that maximum value in range() is n + 1 to make i equal to n on the last step.
๐ŸŒ
Quora
quora.com โ€บ How-would-I-put-for-int-I-10-I-0-i-in-Python
How would I put for (int I = 10; I >= 0; i---) in Python? - Quora
In Python, you can achieve the same result using a for loop with range(). Here's how I would do it: ... This loop starts at 10, goes down to 0 (inclusive), and decrements by 1 on each iteration.
๐ŸŒ
IBM
ibm.com โ€บ reference โ€บ python โ€บ for-loop
What is a for loop in python? | IBM
November 21, 2025 - Understanding how to use loops effectively with these structures is a fundamental skill in Python programming. Range Objects: The range() function returns an iterable that yields a sequence of numbers. It's often used in for loops to specify the number of iterations. for i in range(5): print(i) # prints numbers from 0 to 4
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ for-loops-in-python-with-example-code
For Loops in Python โ€“ For Loop Syntax Example
January 18, 2023 - There is an initialization, i = 0, which acts as the starting point. A condition that needs to be met, i < 5, for the loop to continue to run. An increment operator, i++. Curly braces and the body of the for loop that contains the action to take. A for loop in Python has a shorter, and a more ...