Why use infinite loops?

前端 未结 14 1979
轮回少年
轮回少年 2021-02-08 13:33

Another poster asked about preferred syntax for infinite loops.

A follow-up question: Why do you use infinite loops in your code? I typically see a construct like

14条回答
  •  醉梦人生
    2021-02-08 14:00

    I would consider using an infinite loop to program the guidance system of a missile.

    while ( true ) { go2Target ( ) ; }
    

    From the perspective of the missile's guidance computer, the loop once started does repeat until the end of time.

    Perhaps a purists would favor

    while ( ! blown2Bits ( ) ) { go2Target ( ) ; }
    

    but then how do you implement the blow2Bits method? what would it mean if blow2Bits returned true?

提交回复
热议问题