var i: usize = len; while (i > 0) { i -= 1; // do something } nothing dirty about while loops, that's some organic, gluten-free machine code right there. Healthy CPUs love that shit. Answer from Deleted User on reddit.com
🌐
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?

🌐
GeeksforGeeks
geeksforgeeks.org › python › backward-iteration-in-python
Backward iteration in Python - GeeksforGeeks
July 11, 2025 - a = [1, 2, 3, 4, 5] #Loop through the List # reverse order using slicing(::-1) for item in a[::-1]: print(item) # same logic written using List comprehension # [print(item) for item in a[::-1]] ... Using a while loop provides you control over the iteration process. This is need to manually control the index and decrement the index during each iteration to traverse the it backward.
Discussions

How to Reverse a for loop? [closed] - Stack Overflow
I want to reverse the stars from (smallest to biggest) to (Biggest to smallest) function seethestars1() { for (var i = 0; i More on stackoverflow.com
🌐 stackoverflow.com
bash - How do I reverse a for loop? - Unix & Linux Stack Exchange
As @Gilles said, instead of building an array and then looping over them in reverse order using the O and a parameter expansion flags, you can can directly affect the order of the glob expansion using the oX and OX glob qualifiers. ... Will reverse order your globbed files. On is short for ^on, that is: order by name in reverse. Instead of n for name, the o glob qualifier can also be followed by: ... N Not sort. And ^o or O can be used in place of o to ... More on unix.stackexchange.com
🌐 unix.stackexchange.com
How to reverse the order in a FOR loop
I've a simple FOR statement like this: var num = 10, reverse = false; for(i=0;i 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
🌐
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) ...
🌐
Quora
quora.com › How-do-you-reverse-a-number-in-a-for-loop
How to reverse a number in a for loop - Quora
Then we remove the rightmost digit ... Reversing a number inside a for-loop usually means taking an integer (e.g., 12345) and producing its digits in reverse order (54321)....
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() ...
🌐
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.
🌐
Real Python
realpython.com › python-range
Python range(): Represent Numerical Ranges – Real Python
November 24, 2024 - The range parameters start, stop, and step define where the sequence begins, ends, and the interval between numbers. Ranges can go backward in Python by using a negative step value and reversed by using reversed().
🌐
Codecademy
codecademy.com › article › how-to-reverse-a-list-in-python
How to Reverse a List in Python | Codecademy
To enhance your understanding of Python concepts and dive into more advanced topics, check out the Learn Intermediate Python 3 course from Codecademy. Yes! You can use slicing ([::-1]), reversed(), a for loop, or recursion to reverse a list ...
🌐
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.
🌐
Sololearn
sololearn.com › en › Discuss › 981326 › how-to-reverse-a-number-in-a-for-loop
How to reverse a number in a FOR loop | Sololearn: Learn to code for FREE!
// Not so compact, but no string used : ) // Based on @Dan Walker's suggestion. function reverse2(num){ var rem = 0, digits = 0; var tmp = []; // Collect the digits in reverse, // by adding them in temporary array while (num != 0){ rem = parseInt(num % 10); num = parseInt(num / 10); tmp.push(rem); digits++; } var reversedNum = 0, exp = digits; for(var i = 0; i < digits; i++) { reversedNum += parseInt(tmp[i]) * Math.pow(10, --exp); } return reversedNum; } console.log(reverse(1234)); console.log(reverse2(1234)); ... Hint: number mod 10 (%) gives you the last digit number / 10 (with integer division) gives you the other digits. You can use parseInt or Math.floor to get the integer part of the division. It's a great exercise, I've seen that it is sometimes used as an interview question for grad jobs, but they specifically request no strings!
🌐
JanBask Training
janbasktraining.com › community › python-python › how-do-i-reverse-a-list-or-loop-over-it-backwards
How do I reverse a list or loop over it backwards? | JanBask Training Community
June 4, 2025 - Python offers built-in features that make this process clean and readable. ... The reversed() function returns an iterator that yields the elements of the list in reverse order. my_list = [1, 2, 3, 4, 5] for item in reversed(my_list): print(item)
🌐
GeeksforGeeks
geeksforgeeks.org › r language › reversing-a-vector-using-a-for-loop
Reversing a vector using a for loop? - GeeksforGeeks
July 23, 2025 - Inside the loop, we assign the value of the element at position n - i + 1 in the original vector to the corresponding position i in the reversed_vector. This effectively reverses the order of elements.
🌐
Mimo
mimo.org › glossary › python › for-loop
Python For Loop: Syntax and Examples [Python Tutorial]
You can loop over a sequence in reverse order by using the reversed() Python function. ... Another option is creating a for loop with Python’s range() function and its start, stop, and step parameters. ... Python has libraries like concurrent.futures and pmultiprocessing that allow you to run ...
🌐
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.
🌐
DEV Community
dev.to › tpointtech123 › how-to-reverse-a-string-in-javascript-using-a-for-loop-1aof
How to Reverse a String in JavaScript Using a For Loop - DEV Community
March 20, 2025 - Loop through the original string from the last character to the first. Append each character to the new string in reverse order. Return the newly constructed string. Let’s implement this using a for loop in JavaScript.