for循环

1年前 阅读 210 评论 0 赞 0

for循环
推荐:

  1. for _ in 0..<3 {
  2. print("Hello three times")
  3. }
  4. for (index, person) in attendeeList.enumerated() {
  5. print("\(person) is at position #\(index)")
  6. }
  7. for index in stride(from: 0, to: items.count, by: 2) {
  8. print(index)
  9. }
  10. for index in (0...3).reversed() {
  11. print(index)
  12. }

不推荐:

  1. var i = 0
  2. while i < 3 {
  3. print("Hello three times")
  4. i += 1
  5. }
  6. var i = 0
  7. while i < attendeeList.count {
  8. let person = attendeeList[i]
  9. print("\(person) is at position #\(i)")
  10. i += 1
  11. }
你的支持将鼓励作者继续创作

评论(0)

(无)