swift 2.2循环的新语法

Sta*_*108 2 ios swift swift2.2

我必须修改我的swift 2应用程序的for循环.目前我使用这种语法

for (var x = 0; x < 5; x++) {
Run Code Online (Sandbox Code Playgroud)

我知道我必须使用这个:

for x in 0..<5 {
Run Code Online (Sandbox Code Playgroud)

但我如何改变这个循环:

for (var x = 0; x < 6; x = x+2) {
Run Code Online (Sandbox Code Playgroud)

EI *_*2.0 6

使用stride功能

 // for x<6
 for i in 0.stride(to: 6, by: 2) {
    print(i)   // 0,2,4
 }

 //for x<=6
 for i in 0.stride(through: 6, by: 2) {
    print(i)  // 0,2,4,6
 }
Run Code Online (Sandbox Code Playgroud)