How to break out of multiple loops at once in C#?

前端 未结 4 1165
遥遥无期
遥遥无期 2021-02-02 04:54

What if I have nested loops, and I want to break out of all of them at once?

while (true) {
    // ...
    while (shouldCont) {
        // ...
        while (sho         


        
4条回答
  •  北荒
    北荒 (楼主)
    2021-02-02 05:48

    Extract your nested loops into a function and then you can use return to get out of the loop from anywhere, rather than break.

提交回复
热议问题