When are infinite loops are useful in PHP?

后端 未结 12 904
日久生厌
日久生厌 2020-12-09 21:17

While reading through the great online PHP tutorials of Paul Hudson he said

Perhaps surprisingly, infinite loops can sometimes be h

12条回答
  •  离开以前
    2020-12-09 21:49

    I think a point is being missed... there aren't really infinite loops (you would be stuck in them forever), rather while(true){...} and co are useful when you have non trivial exit conditions (e.g. those coming from a third-party library, or a limit which would take a lot of time to calculate but can be worked out incrementally inside of the loop, or something relying on user input).

    It shouldn't be surprising that not every loop can be concisely stated as a for, while or do loop without using break.

提交回复
热议问题