what is the problem with this?

starting_num = SOME_NUMBER
while True:
    for i in xrange(starting_num, len(array)):
        # do code
    starting_num = 0

it does exactly what you want.

however, i think there are better ways to do things especially if the solution seems "hacky".

if you gave an idea of what you wanted to do, maybe there is a better way

Answer from Inbar Rose on Stack Overflow
Discussions

Python for loop start counter initialization - Stack Overflow
You really should be using enumerate ... and the value at the same time (which will save you the hassle of using two for-loops). ... Your inner loop is overriding the variable index that you defined in the first loop. ... index is being reassigned anyway within the for-loop so ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
python - Initial value of a "for" loop - Stack Overflow
In this loop, if v is not pre-defined, how it is assigned the initial value? for v in birthdays.items(): print(v) break I don't understand the logic. (I was programming with Ba... 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
Why don't we have to initialize the variable of a for loop?
Question In Python, why donโ€™t we have to initialize the variable of a for loop? Answer In Python, a for loop variable does not have to be initialized beforehand. This is because of how Python for loops work. When it runs, the for loop statement will initialize the variable to the first character ... More on discuss.codecademy.com
๐ŸŒ discuss.codecademy.com
0
4
July 28, 2018
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 41668259 โ€บ initial-value-of-a-for-loop
python - Initial value of a "for" loop - Stack Overflow
(I was programming with Basic decades ago and new to Python) ... The code just means only the first value of birthday.items() will be printed -- is that what you're confused about? ... v will take on each value present in birthdays. So the initial value is the first value birthdays.
๐ŸŒ
Kansas State University
textbooks.cs.ksu.edu โ€บ intro-python โ€บ 05-loops โ€บ 03-for-loops โ€บ embed.html
For Loops :: Introduction to Python
June 27, 2024 - As we can see, working with for ... in Python to a while loop. This can be done following a simple three-step pattern: Set an initial value for the iterator variable before the loop...
๐ŸŒ
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). This is less like the for keyword in other programming languages, and works more like an iterator method as found in other object-orientated programming languages. With the for loop we can execute a set of statements, once for each item in a list, tuple, set etc.
Find elsewhere
๐ŸŒ
Berkeley
pythonnumericalmethods.studentorg.berkeley.edu โ€บ notebooks โ€บ chapter05.01-For-Loops.html
For-Loops โ€” Python Numerical Methods
This notebook contains an excerpt ... Berkeley Python Numerical Methods. The copyright of the book belongs to Elsevier. We also have this interactive book online for a better learning experience. The code is released under the MIT license. If you find this content useful, please consider supporting the work on Elsevier or Amazon! < CHAPTER 5. Iteration | Contents | 5.2 While Loops > A for-loop is a set of instructions that is repeated, or iterated, for every value in a ...
๐ŸŒ
Python
wiki.python.org โ€บ moin โ€บ ForLoop
ForLoop - Python Wiki
Many languages have conditions in the syntax of their for loop, such as a relational expression to determine if the loop is done, and an increment expression to determine the next loop value. In Python, this is controlled instead by generating the appropriate sequence. Basically, any object with an ...
๐ŸŒ
Medium
medium.com โ€บ @gewzk โ€บ write-a-for-loop-without-initialization-in-py-js-ruby-8190166f48c
Write a For Loop Without Initialization in Py/JS/Ruby | by Gordon Zeke | Medium
May 18, 2023 - In most programming languages, a for loop requires an initialization statement that sets the initial value of the loop variable. However, there are some languages that allow for loops to execute without initialization.
๐ŸŒ
Delft Stack
delftstack.com โ€บ home โ€บ howto โ€บ python โ€บ python for loop start at 1
How to Start a for Loop at 1 in Python | Delft Stack
March 11, 2025 - Happy coding! How do I start a for loop from a specific number other than 1? You can use the range() function to specify any starting number, like range(start, end). Can I use a for loop to iterate through a dictionary starting at index 1? Yes, ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ how-to-start-a-for-loop-at-1-python
How to start a for loop at 1 - Python - GeeksforGeeks
December 2, 2024 - Python for loops range typically starts at 0. However, there are cases where starting the loop at 1 is more intuitive or necessary such as when dealing with 1-based indexing in mathematics or user-facing applications.
๐ŸŒ
Codecademy Forums
discuss.codecademy.com โ€บ frequently asked questions โ€บ python faq
Why don't we have to initialize the variable of a for loop? - Python FAQ - Codecademy Forums
July 28, 2018 - Question In Python, why donโ€™t we have to initialize the variable of a for loop? Answer In Python, a for loop variable does not have to be initialized beforehand. This is because of how Python for loops work.
๐ŸŒ
Real Python
realpython.com โ€บ python-for-loop
Python for Loops: The Pythonic Way โ€“ Real Python
February 23, 2026 - Note: To learn more about working with enumerate(), check out the Python enumerate(): Simplify Loops That Need Counters tutorial. The enumerate() function also takes an optional argument called start that lets you tweak the initial value. This feature is useful when you need to create counts.
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 62213460 โ€บ initialize-variable-in-for-loop-in-python
Initialize variable in for loop in Python? - Stack Overflow
I just do not want to define the variable "sum" before the loop because it seems so unnecessary. However, I am aware of I have to start that variable otherwise it will give an error or it may be assigned a super unrelated random number which may present its memory address (like in C). So I want to be able to define its initial value once before for loop.
๐ŸŒ
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 - We can start the for a loop at index 1 in several ways in Python, in general, the for loop is used to iterate over a sequence (such as a list,
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ loops-in-python
Loops in Python - GeeksforGeeks
The print() function prints the value of i and moves to the next line after each row. A final note on loop nesting is that we can put any type of loop inside of any other type of loops in Python. For example, a for loop can be inside a while loop or vice versa. Loop control statements change execution from their normal sequence. When execution leaves a scope, all automatic objects that were created in that scope are destroyed. Python supports the following control statements.
Published ย  2 weeks ago
๐ŸŒ
Python Course
python-course.eu โ€บ python3_for_loop.php
20. For Loops | Python Tutorial | python-course.eu
August 16, 2021 - 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 <= ...