Reverse Range in Swift

前端 未结 7 1254
青春惊慌失措
青春惊慌失措 2020-11-27 14:07

Is there a way to work with reverse ranges in Swift?

For example:

for i in 5...1 {
  // do something
}

is an infinite loop.

相关标签:
7条回答
  • 2020-11-27 15:12

    Xcode 7, beta 2:

    for i in (1...5).reverse() {
      // do something
    }
    
    0 讨论(0)
提交回复
热议问题