Click here to Skip to main content
15,884,629 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Let's say I have a for loop like so:
rust
for i in 0..array.len() {}

How would I go forwards/backward in the for loop? It might look like this:

Value of I:
1 > 2 > 3 > 4 > 5 > 3 > 4 > 5 > 6


What I have tried:

I've tried reassigning I, but I don't believe it worked because the for-loop then changes the value of i again.

Thanks in advance,
Uncodeable
Posted
Updated 10-May-22 20:09pm

1 solution

you might use the reverse iterator of the array, e.g.
rust
for i in array.iter().rev()
{
    //..
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900