Is while (true) with break bad programming practice?

后端 未结 22 2316
-上瘾入骨i
-上瘾入骨i 2020-11-27 04:38

I often use this code pattern:

while(true) {

    //do something

    if() {
        break;
    }

}   

Another progr

22条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-27 04:43

    No, that's not bad since you may not always know the exit condition when you setup the loop or may have multiple exit conditions. However it does require more care to prevent an infinite loop.

提交回复
热议问题