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
๐ŸŒ
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).
๐ŸŒ
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 ...
Discussions

"for i in range()" to do an infinite loop with a counter - Ideas - Discussions on Python.org
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. ... More on discuss.python.org
๐ŸŒ discuss.python.org
4
August 10, 2022
A single python loop from zero to n to zero - Stack Overflow
TypeError: unsupported operand ... work in Python 3.4 (does work in 2.7). 2017-06-29T22:45:47.047Z+00:00 ... That is a very cool solution for me since it doesn't require an import and is very easy to read. I made a slight modification because I only want a single zero and 1024 per loop: for i in ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
How do you start a for loop at 1 instead of 0?
Hi! I'm working on a bot to reply with suggestions for common python problems. This might not be very helpful to fix your underlying issue, but here's what I noticed about your submission: You are looping over an object using something like for x in range(len(items)): foo(item[x]) This is simpler and less error prone written as for item in items: foo(item) If you DO need the indexes of the items, use the enumerate function like for idx, item in enumerate(items): foo(idx, item) More on reddit.com
๐ŸŒ r/learnpython
16
6
November 13, 2015
What does "for i in range" mean in Python?
Use a 'code block' in the 'new' reddit to paste code so we can see indents which are vital to python! for i in range(n + 1): sum = sum + i * i * i when you say 'for i in range(n + 1)' you are creating a variable called 'i' and setting it equal to the first value in the second part of the line called range(). every time the loop loops, i becomes the next value in the second part of the line (in this case range()) Check this code out to understand it: my_list = ['potato', 'pineapple', 'strawberry', 'banana', 'orange'] for var in my_list: #instead of 'i' i used 'var' you can use any name you want, since you are creating the variable. var is = to a value in my_list, and will go to the next value every time the loop loops. This will run a total of 5 times, because there are 5 items in the list we are looping through (my_list) print(var) now put that in your terminal/whatever and see the output, itll look like this: potato pineapple strawberry banana orange its the same with range() -- example: range(5) just means every number between 0 and 5, including 0 but not 5. so range(5) has 5 items, 0, 1, 2, 3 and 4. our loop should run 5 times: for i in range(5): print(i) you should see the output: 0 1 2 3 4 if you ever want to know more about certain parts of python, google it, for example: 'python range()' will give you tons of results that are helpful. More on reddit.com
๐ŸŒ r/learnpython
13
17
September 9, 2019
๐ŸŒ
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.
๐ŸŒ
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
๐ŸŒ
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.
๐ŸŒ
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 ...
Find elsewhere
๐ŸŒ
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
๐ŸŒ
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')
๐ŸŒ
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; ...
๐ŸŒ
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.
๐ŸŒ
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.
๐ŸŒ
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.
๐ŸŒ
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.
๐ŸŒ
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 ...
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ python-for-loop-example
Python for loop | DigitalOcean
March 14, 2024 - Lists and Tuples are iterable objects. Letโ€™s look at how we can loop over the elements within these objects now. words= ["Apple", "Banana", "Car", "Dolphin" ] for word in words: print (word) ... Now, letโ€™s move ahead and work on looping over the elements of a tuple here. nums = (1, 2, 3, ...