Try range(100,-1,-1), the 3rd argument being the increment to use (documented here).

("range" options, start, stop, step are documented here)

Answer from 0x6adb015 on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › backward-iteration-in-python
Backward iteration in Python - GeeksforGeeks
July 11, 2025 - a = [10, 20, 30, 40, 50] #Loop through the list #using reversed() to reverse the order of list for b in reversed(a): print(b) ... Let's explore more methods that helps to iterate backward on any iterable. Here are some common approaches: ... range function is provided with three arguments(N, -1, -1). Use this method when we need to modify elements or access their indices. ... s = "Python" # - len(s) - 1: Start at the last index # - -1: Ensures the loop stops after the first character # - -1: The step value to iterate backwards for i in range(len(s) - 1, -1, -1): print(s[i])
Discussions

iteration - How to loop backwards in python? - Stack Overflow
But in Python 3 (which I happen to use) range() returns an iterator and xrange doesn't exist. ... a little too late to answer but, I didn't see the easiest solution here so here it is..........................................................for i in range(n)[::-1] this will give you i in reverse ... More on stackoverflow.com
🌐 stackoverflow.com
How can I loop through an array forward and then backwards and then forwards and... etc with the modulus operator?
Given `n` is 1 less than the length of your array, you can increment and modulus some rotating index `i` against double `n` and then subtract `n`, take the absolute value and you get a bouncing number. It should be noted that you don't need to use any flags as suggested in other comments, but you do lose readability. Explanation: Take your example for an array of length 5, then `n=4`, `i` will rotate through values `[0, 1, 2, 3, 4, 5, 6, 7]` and subtracting `n` from each we get `[-4, -3, -2, -1, 0, 1, 2, 3]`, and the absolute values become `[4, 3, 2, 1, 0, 1, 2, 3]` which you can use to access the values at an index in your array. Try the following code: arr = [1, 2, 3, 4, 5] n = len(arr) - 1 i = n while True: curr_index = abs(i - n) print(arr[curr_index]) i = (i + 1) % (2 * n) and you will get output that looks like: 1 2 3 4 5 4 3 2 1 2 3 4 ... More on reddit.com
🌐 r/learnpython
5
1
September 9, 2021
Is there a way to reverse a for loop
The reversed() function might be what you're looking for. Return a reverse iterator. seq must be an object which has a __reversed__() method or supports the sequence protocol (the __len__() method and the __getitem__() method with integer arguments starting at 0). ie for i in reversed(range(1, 101)): print(i) output: 100 99 98 97 96 ... 5 4 3 2 1 More on reddit.com
🌐 r/learnpython
4
1
March 27, 2020
Why isn't my loop iterating backwards in python?
Hint: Look up documentation on the ‘range’ function…does it actually do what you think it does given the two arguments you provided? Maybe you’re missing an argument? https://docs.python.org/3/library/stdtypes.html#range More on reddit.com
🌐 r/learnprogramming
13
0
March 8, 2023
🌐
Python Morsels
pythonmorsels.com › looping-in-reverse
Looping in reverse - Python Morsels
May 27, 2025 - To loop in the reverse direction, you can use Python's built-in reversed function: >>> colors = ["purple", "blue", "green", "pink", "red"] >>> for color in reversed(colors): ... print("I like", color) ...
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › python for loop in backwards
Python For Loop in Backwards - Spark By {Examples}
May 31, 2024 - Following are the examples of for loop in backwards # Example 1: Get the loop iteration in Backwards # Using reversed() print("Get the loop in backwards") for i in reversed(range(1,6)): # Example 2: Get the for loop in backwards using range() print("Get the loop in backwards") for i in range(6, 0, -1): # Example 3: Get the for loop in backwards using range() & len() # Initialize the list list=[10, 20, 50, 30, 40, 80, 60] print("Get the loop in backwards") for i in range(len(list) -1, -1, -1): # Example 4: Get the loop iterations in Backwards # using slicing list=[10, 20, 50, 30, 40, 80, 60] fo
Find elsewhere
🌐
Mimo
mimo.org › glossary › python › for-loop
Python For Loop: Syntax and Examples [Python Tutorial]
Explore Python For loops to iterate over sequences and execute code efficiently. Learn to use for loops with lists, ranges, and dictionaries for better control.
🌐
Reddit
reddit.com › r/learnpython › how can i loop through an array forward and then backwards and then forwards and... etc with the modulus operator?
r/learnpython on Reddit: How can I loop through an array forward and then backwards and then forwards and... etc with the modulus operator?
September 9, 2021 -

Say I have an array:

arr = [1,2,3,4,5]

and I want to output this using a simple counter and the modulus operator

1 
2
3
4 
5 
4
3 
2
1 
2 
3 
4 
5 
... 

Is this possible? I know that you can loop through an array and start over at the beginning by doing

arr[count % len(arr)]

but how do I just switch directions instead of going back to the beginning?

🌐
Spark By {Examples}
sparkbyexamples.com › home › python › reverse an array in python
Reverse an Array in Python - Spark By {Examples}
May 31, 2024 - Related: In Python, you can use for loop to iterate iterable objects in reversing order and get them in backwards directions.
🌐
Python Tutor
pythontutor.com › visualize.html
Python Tutor - Visualize Code Execution
The user can navigate forwards and backwards through all execution steps, and the visualization changes to match the run-time state of the stack and heap at each step. In this example, the user would see their custom LinkedList data structure getting incrementally built up one Node at a time via recursive calls to init() until the base case is reached when n==0. Despite its name, Python Tutor is also a widely-used web-based visualizer for Java that helps students to understand and debug their code.
🌐
Replit
replit.com › home › discover › how to iterate backwards in python
How to iterate backwards in Python | Replit
3 weeks ago - The reversed() function doesn't create a new, backward list. Instead, it returns an iterator that yields items from the original log_entries list, beginning with the last element.
🌐
TutorialsPoint
tutorialspoint.com › article › backward-iteration-in-python
Backward iteration in Python
2 weeks ago - Python provides three common approaches: range() with negative step, slice notation [::-1], and the reversed() built-in function. Start from the last index and step backwards by -1 until index 0 ? days = ['Mon', 'Tue', 'Wed', 'Thu'] for i in ...
🌐
AWS
aws.amazon.com › blogs › industries › intent-based-nokia-network-slicing-powered-by-amazon-bedrock-enabling-intelligent-adaptive-5g-slicing
Intent-Based Nokia Network Slicing Powered by Amazon Bedrock: Enabling Intelligent, Adaptive 5G Slicing | AWS for Industries
1 month ago - This integrated architecture enables seamless data flow from network infrastructure through intelligent AI processing to autonomous policy deployment, creating a closed-loop system that continuously optimizes network performance without manual intervention. ... Amazon Bedrock AgentCore provides the foundational infrastructure that enables this intent-based network slicing solution to move from prototype to production with enterprise-grade capabilities. AgentCore Runtime delivers a secure, serverless environment purpose-built for deploying and scaling dynamic AI agents, offering extended runtime support for long-running network optimization workflows, true session isolation for secure execution, fast cold starts for rapid response to network changes, and automatic scaling without infrastructure management.
🌐
LeetCode
leetcode.com › problems › reverse-string
Reverse String - LeetCode
Reverse String - Write a function that reverses a string. The input string is given as an array of characters s. You must do this by modifying the input array in-place [https://en.wikipedia.org/wiki/In-place_algorithm] with O(1) extra memory.
🌐
Codemia
codemia.io › knowledge-hub › path › how_to_loop_backwards_in_python_duplicate
How to loop backwards in python?
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises
🌐
Real Python
realpython.com › python-for-loop
Python for Loops: The Pythonic Way – Real Python
1 month ago - Learn how to use Python for loops to iterate over lists, tuples, strings, and dictionaries with Pythonic looping techniques.
🌐
Amanxai
amanxai.com › home › all articles › backward for loop using python
Backward For Loop using Python | Aman Kharwal
October 13, 2021 - Below is how you can use a for loop over a list: list_ = ["Aman", "Kharwal", "Akanksha", "Hritika", "Shiwangi"] for i in list_: print(i) ... Now coming back to using a for loop backwards, Python has an inbuilt function known as reversed() that can ...
🌐
Klipper
klipper3d.org › G-Codes.html
G-Codes - Klipper documentation
STEPPER_BUZZ STEPPER=<config_name>: Move the given stepper forward one mm and then backward one mm, repeated 10 times.
🌐
Codecademy
codecademy.com › article › how-to-reverse-a-list-in-python
How to Reverse a List in Python | Codecademy
In the first approach, reversed() is used with list() to create a new reversed list. In the second approach, reversed() is used directly in a for loop to iterate through elements in reverse order without creating a new list.