为什么下面do-while循环是有效的? [英] Why the following do-while loop is valid?
本文介绍了为什么下面do-while循环是有效的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
的环如下:
do;
while(1);
为什么上面的循环没有给一个语法错误?
Why the above loop is not giving a syntax error?
推荐答案
这code看起来就像是写来混淆它的意义,但如果我们看的草案C99标准部分 6.8.5
迭代语句的,为做语法,同时是:
That code looks like it was written to obfuscate its meaning but if we look at the draft C99 standard section 6.8.5
Iteration statements, the grammar for do while is:
do statement while ( expression ) ;
和语句的可以是一个的前pression声明的这反过来又可以成为一个的空语句的这是什么;
是。因此它是一样的:
and statement can be an expression statement which in turn can be a null statement which is what ;
is. So it is the same as:
do
;
while(1);
我们可以看到部分 6.8.3
的防爆pression和空语句的段落的 3 的说:
一个空语句(只是由分号)不执行任何操作。
A null statement (consisting of just a semicolon) performs no operations.
这篇关于为什么下面do-while循环是有效的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文