//  5, 4 ,3, 2, 1, 0

for index in (0...5).reverse()

{

    print("\(index)")

}

 

//  4 ,3, 2, 1, 0

for index in (0..<5).reverse()

{

    print("\(index)")

}

 

//  5, 4, 3, 2, 1

for index in 5.stride(to: 0, by: -1)

{

    print(index)

}

 

//  5, 4, 3, 2, 1, 0

for index in 5.stride(through: 0, by: -1)

{

    print(index)

}

 

參考資料:

http://stackoverflow.com/questions/35032182/swift-c-style-loops-deprecated-decrement-index

arrow
arrow
    全站熱搜

    小賢 發表在 痞客邦 留言(0) 人氣()