Why is my Swift loop failing with error “Can't form range with end < start”?

后端 未结 6 1630
北海茫月
北海茫月 2021-02-05 01:44

I have a for loop that checks if a number is a factor of a number, then checks if that factor is prime, and then it adds it to an array. Depending on the original number, I wil

6条回答
  •  孤街浪徒
    2021-02-05 02:05

    SWIIFT 4

    The best way to go is to use stride as by this documentation page: Generic Function stride(from:to:by:)

    for i in stride(from: 10, through: 5, by: -1) { print(i) }

    and stride through if you want to include the lowerBound: Generic Function stride(from:through:by:)

提交回复
热议问题