Swift - How to know when a loop has ended?

前端 未结 5 1755
我寻月下人不归
我寻月下人不归 2020-12-30 11:52

Please, forgive me as i\'m very new to swift, and programming in general.

Believe me when I say I\'ve tried hard to understand this, but I simply ca

5条回答
  •  悲哀的现实
    2020-12-30 12:35

    Your print statement always prints out on every loop. Thats why you should put your that statement outside the foreach loop:

    func loop() {
      for i in 0...<5 {
        print(i)
      }
    // it enters here when the loop is finished
      print("loop has finished")
    }
    

提交回复
热议问题