如何在swift中使用for in循环递减条件?

How to use for in loop decrement condition in swift?

我可以通过这段代码在Swift中使用for in循环

   for i in 0..<5
{
    print ("Four multiplied by \(i) results in \(i*4)" )
}

但是我如何使用小于“>”条件的 for。

  for i in 10>..5
{
    print ("Four multiplied by \(i) results in \(i*4)" )
}

显示错误:“>”不是后缀一元运算符 因为我在 10>..5

使用 stride() 方法:

for i in 10.stride(to: 5, by: -1) {
     print ("Four multiplied by \(i) results in \(i*4)" )
}

这将递增到 10、9、8、7 和 6。如果要包括 5,请改用 through:

for i in 10.stride(through: 5, by: -1) {
     print ("Four multiplied by \(i) results in \(i*4)" )
}