range() and xrange() take a third parameter that specifies a step. So you can do the following.

range(10, 0, -1)

Which gives

[10, 9, 8, 7, 6, 5, 4, 3, 2, 1] 

But for iteration, you should really be using xrange instead. So,

xrange(10, 0, -1)

Note for Python 3 users: There are no separate range and xrange functions in Python 3, there is just range, which follows the design of Python 2's xrange.

Answer from Chinmay Kanchi on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › backward-iteration-in-python
Backward iteration in Python - GeeksforGeeks
July 11, 2025 - 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]) ... We can use slicing slicing notation [::-1] ...
Discussions

java - reverse for loop for array countdown - Stack Overflow
An Array in java that has 10 elements ... So your loops need to cover this range. Currently you are going from 0 to 10, and 10 to 0. ... Find the answer to your question by asking. Ask question ... See similar questions with these tags. ... I’m Jody, the Chief Product and Technology Officer at Stack Overflow. Let’s... Release notes and bug fixes for ... More on stackoverflow.com
🌐 stackoverflow.com
c - What's the best way to do a reverse 'for' loop with an unsigned index? - Stack Overflow
My first attempt of reverse for loop that does something n times was something like: for ( unsigned int i = n-1; i >= 0; i-- ) { ... } This fails because in unsigned arithmetic i is More on stackoverflow.com
🌐 stackoverflow.com
bash - How do I reverse a for loop? - Unix & Linux Stack Exchange
How do I properly do a for loop in reverse order? for f in /var/logs/foo*.log; do bar "$f" done I need a solution that doesn't break for funky characters in the file names. More on unix.stackexchange.com
🌐 unix.stackexchange.com
Iteration reverse in for loop
hi all in python if i want to track reverse through the for loop i write this for i in range(len(digits)-1,-1,-1): there is some thing similar in julia ? More on discourse.julialang.org
🌐 discourse.julialang.org
1
0
August 8, 2020
🌐
Reddit
reddit.com › r/zig › is there a proper way to do a reverse for loop?
r/Zig on Reddit: Is there a proper way to do a reverse for loop?
May 29, 2023 -

I'm not finding much about doing a reversed for loop on a slice. Something with this kind of code:

const string: []const u8 = "1234";
for reversed (string) |character| {
    std.debug.print("{}", .{character});
}

And this output:

4
3
2
1

Is there a language feature I'm not aware of, or a function in the std, or should I just use a plain old dirty while loop?

🌐
Fluent C++
fluentcpp.com › home › reverse for loops in c++
Reverse For Loops in C++ - Fluent C++
January 30, 2020 - Let’s see how to traverse a collection backwards by using a range for loop. C++20 will bring ranges to the language, including a range adaptor called std::ranges::views::reverse, or std::views::reverse.
🌐
Medium
travcav.medium.com › why-reverse-loops-are-faster-a09d65473006
A look at reverse loops - Trav Cav - Medium
June 19, 2017 - Putting a number on the stack isn’t so bad but if you’re looping through a few hundred thousand elements then that’s a few hundred thousand times it has to put that number on the stack or whatever functionality you put there. Sure a few hundred thousand extra instructions probably isn’t the worst thing in the world, but if you put a function there that takes an extra millisecond then you’ve just added minutes to your code. And hey if you’re bothering to use a reverse For Loop then you care about those cycles.
Find elsewhere
🌐
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] for i in list[-1::-3]: # Example 5: Get the for loop index in backwards using range() & len() # Initialize the list list=[10, 20, 50, 30, 40, 80, 60] print("Get the loop index in backwards") for i in range(len(list) -1, -1, -1): # Example 6: Get the index and items of list in backward direction.
🌐
Jennerstrand
jennerstrand.se › home › reverse for loop in c# – a quick look
Reverse FOR loop in C# - A quick look - Eric Sjöström Jennerstrand
December 5, 2020 - Reverse FOR loop in C# are useful if you need to iterate a List backwards without first reversing. for (int i = list.Count - 1; i >= 0; i--)
🌐
AlgoCademy
algocademy.com › link
Looping In Reverse in Java | AlgoCademy
In this lesson, we covered how to use a for loop to count backwards in Java. We discussed the basic concepts, provided examples, and highlighted common pitfalls and best practices. Mastering reverse loops is essential for writing efficient and readable code.
🌐
MathWorks
mathworks.com › matlab coder › performance › execution speed
coder.loop.reverse - Reverse loop iteration order in generated code - MATLAB
coder.loop.reverse("loopID") prompts the code generator to reverse the loop iteration order for the for-loop whose index name is loopID in the generated code.
🌐
Unreal Engine
forums.unrealengine.com › development › programming & scripting › blueprint
Reverse For Loop for Components - Blueprint - Epic Developer Community Forums
September 28, 2016 - Hello there, Update: To anyone with the same problem, you must use a Reverse For Loop to make this work: [A Little Tip] Remove elements from an array in one pass with a reverse for loop - Programming & Scripting - Unr…
🌐
Baeldung
baeldung.com › home › scripting › iterating in reverse using for loops and other constructs
Iterating in Reverse Using for Loops and Other Constructs | Baeldung on Linux
March 18, 2024 - Next, we decrement this index to zero one by one, outputting the i-th element at every iteration. In Bash, array indexing starts at 0. The tac command is the reverse of the cat command, i.e., it prints the lines of its input in reverse order.
🌐
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) ...
🌐
AlgoCademy
algocademy.com › link
Looping In Reverse in JavaScript | AlgoCademy
This code iterates over an array in reverse order, printing each element. Here is the complete code implementation for the assignment: ... Use console.log: Print the loop variable at each iteration to verify its value.
🌐
Mkyong
mkyong.com › home › java › java – reverse loop versus forward loop in performance
Java - Reverse loop versus Forward loop in Performance - Mkyong.com
November 26, 2018 - This is totally wrong If you correct the mistake pointed out by Flix, the forward loop is faster then reverse.