What is the shortest way to run same code n times in Swift?

后端 未结 13 2215
遥遥无期
遥遥无期 2021-02-01 00:58

I have a code that I need to run exactly n times in Swift. What is the shortest possible syntax for that?

I am currently using the for loop but

相关标签:
13条回答
  • 2021-02-01 01:27

    The only loop shorter than that is an infinite while loop:

    while (true) {
    }
    

    But you would still have to increase a counter and check it in the loop to break the loop, and in the end it wouldn't be shorter.

    0 讨论(0)
提交回复
热议问题