Can't form Range with end < start Check range before doing for loop?

后端 未结 3 685
孤城傲影
孤城傲影 2020-12-19 11:07

I\'m encountering a change in the swift code which i do not quite understand.

var arr = []
for var i = 1; i <= arr.count; i += 1
{
    print(\"i want to          


        
3条回答
  •  萌比男神i
    2020-12-19 11:20

    The obvious solution in this case would be:

    var arr = []
    for i in arr.indices {
        print("I want to see the i \(i)") // 0 ... count - 1
        print("I want to see the i \(i + 1)") // 1 ... count
    }
    

    but carefully read through originaluser2's answer

提交回复
热议问题