久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

為什么for循環(huán)的條件可以留空?

Why can the condition of a for-loop be left empty?(為什么for循環(huán)的條件可以留空?)
本文介紹了為什么for循環(huán)的條件可以留空?的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

可能的重復(fù):
for 和 while 循環(huán)中沒(méi)有循環(huán)條件

為什么允許 for 循環(huán) 中的條件為空?例如

Why is the condition in a for-loop allowed to be left empty? For example

for (;;)

編譯正常.為什么這個(gè)空表達(dá)式的計(jì)算結(jié)果為 true 而下面的

compiles fine. Why does this empty expression evaluate to true but the following

if () {}
while () {}

兩者都會(huì)失敗嗎?我想知道是否/為什么for循環(huán)是這種情況的一個(gè)例外.

will both fail? I want to know if/why the for-loop is an exception to this case.

推薦答案

http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1256.pdf

這些是迭代語(yǔ)句

while(表達(dá)式)語(yǔ)句

while ( expression ) statement

do 語(yǔ)句 while ( 表達(dá)式 ) ;

do statement while ( expression ) ;

for ( 表達(dá)式 [opt] ; 表達(dá)式 [opt] ; 表達(dá)式 [opt] ) 語(yǔ)句

for ( expression [opt] ; expression [opt] ; expression [opt] ) statement

for ( 聲明表達(dá)式 [opt] ; 表達(dá)式 [opt] ) 語(yǔ)句

for ( declaration expression [opt] ; expression [opt] ) statement

while 循環(huán)旨在評(píng)估控制表達(dá)式before 每次執(zhí)行循環(huán),而 do 循環(huán)旨在評(píng)估after 每次執(zhí)行.

The while loop was designed to evaluate the controlling expression before each execution of the loop and the do loop was designed to evaluate after each execution.

for 循環(huán)被設(shè)計(jì)為更復(fù)雜的迭代語(yǔ)句.

The for loop was designed as a more sophisticated iteration statement.

6.8.5.3 for 語(yǔ)句

6.8.5.3 The for statement

聲明

for ( clause-1 ; expression-2 ; expression-3 ) 語(yǔ)句

for ( clause-1 ; expression-2 ; expression-3 ) statement

行為如下:表達(dá)式 expression-2 是控制表達(dá)式,即在每次執(zhí)行循環(huán)體之前評(píng)估.表達(dá)方式每次執(zhí)行后,表達(dá)式 3 被評(píng)估為一個(gè)空表達(dá)式循環(huán)體.如果子句 1 是聲明,則任何它聲明的標(biāo)識(shí)符是聲明的其余部分,而整個(gè)循環(huán),包括其他兩個(gè)表達(dá)式;它是在首次評(píng)估控制之前的執(zhí)行順序表達(dá).如果子句 1 是表達(dá)式,則將其計(jì)算為 void控制表達(dá)式的第一次計(jì)算之前的表達(dá)式.

behaves as follows: The expression expression-2 is the controlling expression that is evaluated before each execution of the loop body. The expression expression-3 is evaluated as a void expression after each execution of the loop body. If clause-1 is a declaration, the scope of any identi?ers it declares is the remainder of the declaration and the entire loop, including the other two expressions; it is reached in the order of execution before the ?rst evaluation of the controlling expression. If clause-1 is an expression, it is evaluated as a void expression before the ?rst evaluation of the controlling expression.

子句 1 和表達(dá)式 3 都可以省略.一個(gè)省略表達(dá)式 2 被一個(gè)非零常量替換.

Both clause-1 and expression-3 can be omitted. An omitted expression-2 is replaced by a nonzero constant.

規(guī)范允許表達(dá)式 2(循環(huán)的條件)被省略,并由一個(gè)非零常量代替.這意味著 for 循環(huán)將無(wú)限期地繼續(xù)執(zhí)行.

The specification allows expression-2, the condition of the loop, to be omitted and is replaced by a nonzero constant. This means that the for loop will continue to execute indefinitely.

這對(duì)于允許無(wú)止境迭代的簡(jiǎn)單語(yǔ)法很有用.

This is useful for allowing a simple syntax for iterating with no end.

for(int i = 0;;i++) { //do stuff with i }

這比編寫一個(gè)在循環(huán)外聲明變量然后在循環(huán)內(nèi)遞增的 while(1) 循環(huán)要簡(jiǎn)單得多.

That's much simpler to write and understand than writing a while(1) loop with a variable declared outside the loop and then incremented inside the loop.

然后,for 循環(huán)規(guī)范繼續(xù)允許您省略子句 1,以便您可以在其他地方聲明或初始化變量,并且您可以省略表達(dá)式 3,以便您不需要在每個(gè)循環(huán)完成時(shí)評(píng)估任何表達(dá)式.

The for loop specification then goes on to allow you to omit clause-1 so that you can declare or initialize variables elsewhere, and you can omit expression-3 so that you are not required to evaluate any expression upon completion of each loop.

for 循環(huán)是一個(gè)特例.while 循環(huán)和 do 循環(huán)是嚴(yán)格的,需要一個(gè)表達(dá)式,而 for 循環(huán)是一個(gè)靈活的迭代語(yǔ)句.

The for loop is a special case. The while loop and the do loop are strict and require an expression, but the for loop is a flexible iteration statement.

這篇關(guān)于為什么for循環(huán)的條件可以留空?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

What do compilers do with compile-time branching?(編譯器如何處理編譯時(shí)分支?)
Can I use if (pointer) instead of if (pointer != NULL)?(我可以使用 if (pointer) 而不是 if (pointer != NULL) 嗎?)
Checking for NULL pointer in C/C++(在 C/C++ 中檢查空指針)
Math-like chaining of the comparison operator - as in, quot;if ( (5lt;jlt;=1) )quot;(比較運(yùn)算符的數(shù)學(xué)式鏈接-如“if((5<j<=1)))
Difference between quot;if constexpr()quot; Vs quot;if()quot;(“if constexpr()之間的區(qū)別與“if())
C++, variable declaration in #39;if#39; expression(C++,if 表達(dá)式中的變量聲明)
主站蜘蛛池模板: 四虎影院最新地址 | 丰满少妇在线观看网站 | 国产aⅴ爽av久久久久成人 | 中文字幕视频一区 | 男人天堂av网 | 91tv国产成人福利 | 三级在线播放 | 国产一区二区三区在线观看视频 | a在线视频 | 国产永久免费视频 | 黄色精品网站 | 免费人成 | 欧美一区二区在线播放 | 18国产免费视频动漫 | 一本久久道| 黄色免费av | 亚洲福利网站 | 国产成人片 | 亚洲日本视频 | 欧美日韩一 | 日本一级淫片色费放 | 成人理论影院 | 日韩 欧美 | 日韩欧美高清视频 | 国产一级黄色 | 亚洲黄色天堂 | a毛片大片 | 成人一级黄色片 | 日本久久精品 | 懂色av一区二区夜夜嗨 | 黄在线观看 | 黄色日批视频 | 高清国产mv在线观看 | 日韩精品一区在线 | 成年人免费视频网站 | 91亚洲精品乱码久久久久久蜜桃 | 中文字幕免费在线观看 | 亚洲欧美另类在线观看 | 亚洲精品观看 | 日日夜夜精品免费 | 中国黄色录像 |