Is there ever a need for a “do {…} while ( )” loop?

后端 未结 19 2306
清歌不尽
清歌不尽 2020-11-29 02:44

Bjarne Stroustrup (C++ creator) once said that he avoids \"do/while\" loops, and prefers to write the code in terms of a \"while\" loop instead. [See quote below.]

S

19条回答
  •  鱼传尺愫
    2020-11-29 03:00

    (Assuming you know the difference between the both)

    Do/While is good for bootstrapping/pre-initializing code before your condition is checked and the while loop is run.

提交回复
热议问题