最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

[已解决]swift跳出for循环

Swift crifan 6706浏览 0评论

想要实现类似于这样的效果:

        var hasInserted:Bool = false
        for 。。。in 。。。。 {
。。。
            if。。。

                hasInserted = true
            }
        }
for循环中,当满足某个条件,想要直接退出for循环
搜:
swift for jump out
swift for in break
Break in a Loop Statement
When used inside a loop statement, break ends the loop’s execution immediately, and transfers control to the first line of code after the loop’s closing brace (}). No further code from the current iteration of the loop is executed, and no further iterations of the loop are started.
->
所以在for循环中,直接用break:
        var hasInserted:Bool = false
        for 。。。in 。。。。 {
。。。
            if。。。

                hasInserted = true
                break
            }
        }
 即可。

转载请注明:在路上 » [已解决]swift跳出for循环

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
84 queries in 0.179 seconds, using 22.01MB memory