From the documentation:

range([start], stop[, step])

The start defaults to 0, the step can be whatever you want, except 0 and stop is your upper bound, it is not the number of iterations. So declare n to be whatever your upper bound is correctly and you will not have to add 1 to it.

e.g.

>>> for i in range(1, 7, 1): print(i)
... 
1
2
3
4
5
6
>>> for i in range(1, 7, 2): print(i)
... 
1
3
5

A nice feature, is that it works in reverse as well.

>>> for i in range(7, 0, -1): print(i)
... 
7
6
5
4
3
2
1

If you aren't using it as an index but for something that can have positive or negative values, it still comes in handy:

>>> for i in range(2, -3, -1): print(i)
... 
2
1
0
-1
-2
>>> for i in range(-2, 3, 1): print(i)
... 
-2
-1
0
1
2
Answer from Rolf of Saxony on Stack Overflow
๐ŸŒ
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.
๐ŸŒ
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. To iterate over a decreasing sequence, we can use an extended form of range() with three arguments - range(start_value, end_value, step). When omitted, the step is implicitly equal to 1. However, can be any non-zero value. The loop always includes start_value and excludes end_value during iteration:
Discussions

python - Pythonic way to iterate through a range starting at 1 - Stack Overflow
Currently if I want to iterate 1 through n I would likely use the following method: for _ in range(1, n+1): print(_) Is there a cleaner way to accomplish this without having to reference n + 1... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Python basics printing 1 to 100 - Stack Overflow
My question is: When I try to increment ... count=count+1 I get an infinite loop - why is that? ... This question appears to be off-topic because the problem cannot be reproduced with the code in question. ... The answers here have pointed out that because after incrementing count it doesn't equal exactly 100, then it keeps going as the criteria isn't met (it's likely you want < to say less than 100). I'll just add that you should really be looking at Python's builtin ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Understanding Range() function in python. [Level: Absolute Beginner]
You can think of range as returning a sequence of numbers. Since we use the syntax for in : to loop or iterate over a sequence, naturally we can put a range as the sequence. Does that help? More on reddit.com
๐ŸŒ r/learnpython
23
4
August 6, 2024
New to python and I need some help with loops.
Loops allow you to repeat a block of code over and over again. There are two main types of loops in Python - for loops and while loops. For loops are used when you know how many times you want to repeat the code. # This will print the numbers 0 to 4 for i in range(5): print(i) The range(5) part creates numbers from 0 to 4. The for loop will go through each of those numbers, storing them in the variable i, and print them out. While loops are used when you don't know exactly how many times you need to repeat the code. You keep looping as long as some condition is true. # This will print numbers as long as x is less than 5 x = 0 while x < 5: print(x) x = x + 1 This starts x at 0, then keeps looping as long as x is less than 5. Each time, it prints x and then adds 1 to x. Once x reaches 5, the loop stops. More on reddit.com
๐ŸŒ r/learnpython
12
6
August 31, 2023
๐ŸŒ
Python
wiki.python.org โ€บ moin โ€บ ForLoop
ForLoop - Python Wiki
Like the while loop, the for loop can be made to exit before the given object is finished. This is done using the break statement, which will immediately drop out of the loop and continue execution at the first statement after the block. You can also have an optional else clause, which will run should the for loop exit cleanly - that is, without breaking. ... list_of_lists = [ [1, 2, 3], [4, 5, 6], [7, 8, 9]] for list in list_of_lists: for x in list: print(x)
๐ŸŒ
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
๐ŸŒ
Django Central
djangocentral.com โ€บ python-program-to-print-numbers-from-1-to-10-using-for-loop
Python Program To Print Numbers From 1 to 10 Using For Loop
The for loop is used to iterate through the range of numbers from 1 to 10 (inclusive). The range() function generates a sequence of numbers, starting from the first argument (1) up to, but not including, the second argument (11), similar to list indexing in range starts from 0 which means range( ...
๐ŸŒ
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.
Find elsewhere
๐ŸŒ
Python Course
python-course.eu โ€บ for_loop.php
20. For Loops | Python Tutorial | python-course.eu
Write a program to find and print all prime numbers between 1 and 50 using a for loop. Print numbers from 1 to 42, but for multiples of 3, print "Fizz," and for multiples of 5, print "Buzz." For numbers that are multiples of both 3 and 5, print "FizzBuzz."
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ python-for-loop-for-i-in-range-example
Python For Loop - For i in Range Example
March 30, 2021 - # More complex example for i in [1, 3, 5, 7, 9]: x = i**2 - (i-1)*(i+1) print(x, end=", ") # prints 1, 1, 1, 1, 1, When the values in the array for our for loop are sequential, we can use Python's range() function instead of writing out the contents of our array.
๐ŸŒ
Great Learning
mygreatlearning.com โ€บ blog โ€บ it/software development โ€บ for loop in python with examples
For Loop in Python with Examples
August 15, 2024 - The "range()" function generates a sequence of numbers that can be used to control the number of loop iterations. Here's an example of using "range()" in a "for" loop: ... In this case, the loop iterates over the numbers 1 to 5 (inclusive).
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ gloss_python_for_range.asp
Python Looping Through a Range
โฎ Python Glossary ยท 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 ...
๐ŸŒ
Real Python
realpython.com โ€บ python-for-loop
Python for Loops: The Pythonic Way โ€“ Real Python
February 23, 2026 - To avoid unnecessary work, the loop should terminate once it finds the target value. You can do this with the break statement: ... >>> numbers = [1, 3, 5, 7, 9] >>> target = 5 >>> for number in numbers: ...
๐ŸŒ
InterServer
interserver.net โ€บ home โ€บ python โ€บ how to use the range() function in python loops with examples
How to Use the range() Function in Python Loops With Examples - Interserver Tips
August 4, 2025 - Letโ€™s say you want to find the sum of numbers from 1 to n. You can use range() in a loop to add them one by one. n = 5 total = 0 for i in range(1, n + 1): total += i print("Sum is:", total)
๐ŸŒ
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.
๐ŸŒ
Bobby Hadz
bobbyhadz.com โ€บ blog โ€บ python-for-loop-1-to-10
For or While loop to print Numbers from 1 to 10 in Python | bobbyhadz
April 9, 2024 - If the condition is met, we use the break statement to exit the while loop. The break statement breaks out of the innermost enclosing for or while loop. If the condition isn't met, the number variable is in the specified range (1 to 10), so we print its value and increment it by 1.
๐ŸŒ
Salford PsyTech Home
hub.salford.ac.uk โ€บ home โ€บ python โ€บ loops โ€“ python
Loops - Python - Salford PsyTech Home โ†’โŒ‚
July 19, 2022 - Loops allow up to repeat code and iterate over large data sets. The latter, weโ€™ll be getting more into in the next session. Loops come in two varieties, you have while loops and for loops. While loops will run the code while a condition is met. For loops will run the code for a specified [โ€ฆ]
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ python-for-loop-example
Python for loop | DigitalOcean
March 14, 2024 - We can iterate over the list of numbers and if the number is found, break out of the loop because we donโ€™t need to keep iterating over the remaining elements. In this case, weโ€™ll use the Python if else condition along with our for loop. nums = [1, 2, 3, 4, 5, 6] n = 2 found = False for num in nums: if n == num: found = True break print(f'List contains {n}: {found}') # Output # List contains 2: True
๐ŸŒ
Berkeley
pythonnumericalmethods.studentorg.berkeley.edu โ€บ notebooks โ€บ chapter05.01-For-Loops.html
For-Loops โ€” Python Numerical Methods
Inner for-loop begins with looping variable, j, set to 0. s is incremented by x[i,j] = x[0,0] = 5. So s = 5. Inner for-loop sets j = 1.
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ for-loop
Python for Loop (With Examples)
Here, we have printed each character of the string language using a for loop. In Python, the range() function returns a sequence of numbers. For example, # generate numbers from 0 to 3 values = range(0, 4) Here, range(0, 4) returns a sequence of 0, 1, 2 , and 3.