for the code,

for i in range(0,10):
   if i == 3:
       i = i + 1
       continue
   print(i)

the output is going to be,

0
1
2
4
5
6
7
8
9

Breaking down the code,

for i in range(0, 10)

for loop runs for i=0 to i=9, each time initializing i with the value 0 to 9.

if i == 3:
 i = i + 1
 continue
print(i)

when i = 3, above condition executes, does the operation i=i+1 and then continue, which looks to be confusing you, so what continue does is it will jump the execution to start the next iteration without executing the code after it in the loop, i.e. print(i) would not be executed.

This means that for every iteration of i the loop will print i, but when i = 3 the if condition executes and continue is executed, leading to start the loop for next iteration i.e. i=4, hence the 3 is not printed.

Answer from developer6811 on Stack Overflow
Discussions

How do I increment a counter inside a while test of Python - Stack Overflow
The word "limitation" was born in my mind due to long-term communication with Ruby-guys and in Ruby everything is an expression). 2012-09-08T15:19:23.35Z+00:00 ... @user1656850: the code in the answer as it stands now increments i, then does the test. It's functionally the same. 2012-09-08T15:20:19.853Z+00:00 ... @user1656850: your analysis of the example is wrong. The Python while loop ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
March 12, 2024
python - Increment and while loop - Stack Overflow
Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... I can see Hello World printed 5 times however when entering spam in IDLE, I can see the integer 5. Shouldn't this be logically int 6 since while loop will stop as soon as the spam is incremented by ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
How do I increment a value in a while loop in Python>? - Stack Overflow
I'm trying to find the area of a space under a curve on a graph. This is being done by getting the area of multiple rectangles with a constant base but incrementing heights. The rectangles are betw... More on stackoverflow.com
๐ŸŒ stackoverflow.com
October 1, 2022
Help on where to put the increment function on while loops

So let me say this first. If

x = root**pwr 

then

root = x**(1/pwr)

Does this help?

More on reddit.com
๐ŸŒ r/learnpython
14
4
December 15, 2022
๐ŸŒ
Tutorial Gateway
tutorialgateway.org โ€บ python-while-loop
Python While Loop
March 25, 2025 - The condition (number<= 10) checks whether the number is less than or equal to 10. If the expression result is true, the number is added to the total. Next, We used + to increment the number value in the Python while loop.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ specifying-the-increment-in-for-loops-in-python
Specifying the increment in for-loops in Python - GeeksforGeeks
July 15, 2025 - Depending on how many arguments the user is passing to the function, the user can decide where that series of numbers will begin and end as well as how big the difference will be between one number and the next. ... Example 1: Incrementing the iterator by 1. ... Example 2: Incrementing the iterator by an integer value n. ... Example 3: Decrementing the iterator by an integer value -n. ... Example 4: Incrementing the iterator by exponential values of n.
๐ŸŒ
CodeGym
codegym.cc โ€บ java blog โ€บ learning python โ€บ increment and decrement in python
Increment and Decrement in Python
November 11, 2024 - Although Python doesnโ€™t include ++ and -- operators, it offers plenty of straightforward ways to increment and decrement values. Use += for incrementing and -= for decrementing. Consider using i = i + 1 or i = i - 1 for explicit code.
๐ŸŒ
Thinglabs
thinglabs.io โ€บ python-increment-by-1-a-guide-to-simple-counting-in-code
Python Increment by 1: A Guide to Simple Counting in Code - thinglabs
November 7, 2024 - ... This loop continues running and incrementing count until count is equal to 5. Each iteration increases count by 1 using the += operator, which is the standard way to increment a value in Python...
Find elsewhere
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ ways-to-increment-iterator-from-inside-the-for-loop-in-python
Ways to increment Iterator from inside the For loop in Python - GeeksforGeeks
January 22, 2026 - In Python, a for loop iterates over an iterator object rather than using a manual counter. As a result, modifying the loop variable inside the loop does not affect iteration, and controlled stepping must be handled explicitly. Example: Why Incrementing the Loop Variable Does Not Work
๐ŸŒ
iO Flood
ioflood.com โ€บ blog โ€บ python-increment-by-1-quick-and-easy-examples
Python Increment By 1 | Quick and Easy Examples
March 12, 2024 - This code will print the numbers 1 to 5. It starts with x at 0 and increments x by 1 in each iteration of the loop, halting once x is no longer less than 5. You can also embed conditions within loops for more complex operations. For example, you could increment a value within a while loop, but only if the value meets a certain condition.
๐ŸŒ
Replit
replit.com โ€บ home โ€บ discover โ€บ how to increment a variable in python
How to increment a variable in Python | Replit
February 12, 2026 - To safely modify a list while looping, iterate over a copy of it. You can create a copy with slice notation, like this: for item in my_list[:]:. This lets you change the original list without disrupting the loop.
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 73915441 โ€บ how-do-i-increment-a-value-in-a-while-loop-in-python
How do I increment a value in a while loop in Python>? - Stack Overflow
October 1, 2022 - Try increment left end point variable a instead of defining and incrementing x. print("Computing the area under the curve x^2 + x + 1") a = int(input("Enter the left end point a: x = ")) b = int(input("Enter the right end point b: x = ")) base = 0.1 total_area = 0 while (a <= b): sub_area = (a**2 + a + 1) * base total_area += sub_area a += base print("The area under the curve is " + str(total_area)) ... Sign up to request clarification or add additional context in comments. ... In each loop, you have to let a add 0.1.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ help on where to put the increment function on while loops
r/learnpython on Reddit: Help on where to put the increment function on while loops
December 15, 2022 -

Please help me understand how the root and the pwr increments were placed down below on the following code

    # 

============================================================================= # Write a program that asks the user to enter an integer and prints two integers, root and pwr, such that 0 < pwr < 6 and root**pwr is equal to the integer entered by the user. If no such pair of integers exists, it should print a message to that effect. #

x = int(input('Enter an integer:'))
pwr = 1
while pwr < 6:
    if x < 0:
        root = x
    else:
        root = 0
    while root**pwr <= x:
        #print(root,'**',pwr)
        if root**pwr == x:
            print(root, '**', pwr, '=', x)
        else:
            if x**1 != x:
                print('No such integer pairs exist')
        root += 1
    pwr += 1

Top answer
1 of 2
3

So let me say this first. If

x = root**pwr

then

root = x**(1/pwr)

Does this help?

2 of 2
2

You're trying to understand the structure of the while loop? It's arranged like this:

while root**pwr <= x:
    (check if this value of root is a solution)
    (otherwise, increase root to get ready for the next attempt)

The condition root**pwr <= x will keep trying as long as root is small enough that it might be a potential solution. Once root**power > x, you know that you're never going to have a solution. Incrementing root any more will never get to a solution. So you give up at that point.

Why is the increment at the bottom? Think about the order of events. In a while loop, first it tests the condition, then if the condition is true it executes the code inside the loop. So you have this loop:

  • check if root is within the valid range (that's the while condition)

  • if so, check if root is a solution

  • increment root and go back to the top

So the next thing after incrementing is to check if root is in range and stop if not.

If you put the increment at the top of the loop, you'd have this:

  • check if root is within the valid range

  • if so, increment it (now it might not be in range any more!)

  • see if root is a solution.

  • go back to the top

You don't want to check invalid values. You want to stop as soon as root gets too big.

The other problem is what happens with the starting value, root = x or root = 0? If the first thing you did was increment before checking, then you never try those values. You immediately jump to x + 1 or 0 + 1 as the first thing to test.

๐ŸŒ
datagy
datagy.io โ€บ home โ€บ python posts โ€บ python increment and decrement operators: an overview
Python Increment and Decrement Operators: An Overview โ€ข datagy
December 16, 2022 - In many cases, you can easily set a loop to continue running until a value is equal to a certain value. For example, you can set a loop to run ten times by incrementing a value by 1:
๐ŸŒ
CodeRivers
coderivers.org โ€บ blog โ€บ increments-python
Python Increment Operators: A Comprehensive Guide - CodeRivers
March 18, 2025 - # Incorrect - infinite loop count = 0 while count < 5: print(count) # Missing increment operation ยท To fix this, we need to add count += 1 inside the loop. Make sure the data type of the variable you are incrementing is appropriate for the operation. For example, if you are incrementing a ...
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ python โ€บ how to increment for loop in python
How to Increment For Loop in Python - Spark By {Examples}
May 31, 2024 - ... Python range() function is used to generate a sequence of numbers within a given range. By default using the range() function in a for loop, the loop will be incremented by โ€˜1โ€™ for every iteration.
๐ŸŒ
Codecademy
codecademy.com โ€บ forum_questions โ€บ 508fe06f900ba10200002d7f
the for loop increment | Codecademy
My code for the Blast Off exercise works, so long as my for loops increment section reads as follows (I include the entire line of the for loop) : ... The browser actually freezes, apparently given the change to the increment section. Interestingly, in section 2 of the โ€œArt of Loopingโ€ lesson, the for loopโ€™s increment section read as counter = counter + 1.
๐ŸŒ
CodeGenes
codegenes.net โ€บ blog โ€บ how-to-increment-in-python
How to Increment in Python: A Comprehensive Guide โ€” codegenes.net
January 9, 2026 - Incrementing is commonly used in loops to iterate over a sequence or perform a certain number of operations. # Using a for loop with a range for i in range(5): print(i) # Output: 0, 1, 2, 3, 4 # Using a while loop count = 0 while count < 5: print(count) count += 1 # Incrementing the counter
๐ŸŒ
Python Guides
pythonguides.com โ€บ increment-and-decrement-operators-in-python
Increment and Decrement Operators in Python
September 2, 2025 - Output: Within the loop, we increment the total_cars variable by 1 for each car passing through using the += operator in Python.