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

前端 未结 6 1082
抹茶落季
抹茶落季 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:38

    The difference between logical statements used in while() and for(;;) loops is that:

    • in case of for the statement defines condition of exiting the loop

    • in case of while() the statement defines condition of executing the loop

    Assuming that, you see that to enter a loop, you need at least a condition of executing, not a condition of exiting.

提交回复
热议问题