0

What is the syntax of a decrementing for() loop?

I would like to do something like the following without getting a compilation error:

for ndx in 5...4 {
    print("do something")
}
Frederick C. Lee
  • 9,019
  • 17
  • 64
  • 105
  • 1
    Do make sure to jump down to the highest-rated (but not accepted) answer. In your example: `for ndx in (4...5).reversed() {` – Rob Napier Oct 14 '16 at 21:05
  • I found another soln via stride() at: [stride](http://stackoverflow.com/questions/24508592/how-to-iterate-for-loop-in-reverse-order-in-swift) – Frederick C. Lee Oct 14 '16 at 21:12

1 Answers1

7

This prints the value of i in reverse order:

for i in (1...10).reversed() {
print(i)
}
Mago Nicolas Palacios
  • 2,501
  • 1
  • 15
  • 27