while循环需要显式条件

while循环需要显式条件

本文介绍了while循环需要显式条件,for循环不,为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C ++中,允许在for循环中有一个空条件,例如 for(;;) for int x = 0 ;; ++ x)。但是你不能做 while()

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 while ().

当在for循环中省略条件时,要 true (所以循环永远循环)。为什么循环不是这种情况,也就是说,不允许 while() 的别名

When condition is omitted inside the for loop, condition is assumed to be true (so the loop loops forever). Why isn't this the case with while loops, that is, what's the argument behind not letting while () be an alias of while (true)?

推荐答案

在for语句中每个给定的子句是可选的事实的副作用。有一些原因为什么一些for循环不需要一个赋值;有理由为什么有些人不需要条件;有其他人不需要增量的原因。要求有一定的最小数量将是不必要的增加的复杂性。

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.

这篇关于while循环需要显式条件,for循环不,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 11:24