Swift how to iterate float
问题 I tried to find this in Swift 2 docs, but can't find any info how to iterate floats. New swift iteration style make me crazy =) with dots and etc. for (i = 0; i < 100; i+=0.5) how to write it in Swift? This does not work as it's Double: for _ in 5.0.stride(100.0, by: 0.5) { } 回答1: This is the (exact) equivalent of your C-loop using stride Swift 2 for index in 0.0.stride(to: 99.5, by: 0.5) { print(index) } Swift 3 for index in stride(from:0.0, through: 99.5, by: 0.5) { print(index) } 来源: https