while loop requires explicit condition, for loop doesn't, why?

前端 未结 6 1087
抹茶落季
抹茶落季 2021-01-03 20:51

In C++ you are allowed to have an empty condition inside the for-loop, for example as in for (;;) or for (int x = 0;; ++x). But you can\'t do

6条回答
  •  暖寄归人
    2021-01-03 21:18

    Presumably, it's a side-effect of the fact that each given clause within the for-statement is optional. There's reasons why some for-loops wouldn't need an assignment; there's reasons why some others wouldn't need a condition; there's reasons why still others wouldn't need an increment. Requiring there to be some minimum number of them would be needlessly-added complexity.

提交回复
热议问题