Best refactoring for the dreaded While (True) loop

前端 未结 12 962
感动是毒
感动是毒 2021-02-04 10:27

If, like me, you shiver at the site of a While (True) loop, then you too must have thought long and hard about the best way to refactor it away. I\'ve seen several different im

12条回答
  •  清歌不尽
    2021-02-04 11:08

    Do we really need to refactor while(true) loops? Sometimes it's a coding standard and most of the developers has got used to this structure. If you have to think hard on how to refactor this code, are you sure it's a good idea to refactor it?

    Goto used to be a black sheep in coding standards. I've met algorithms where goto made the code much more readable and shorter. Sometimes it doesn't worth to refactor (or better to use goto).

    On the other hand you can avoid while(true) most of the time.

提交回复
热议问题