C中的“do”关键字

3yhwsihp  于 5个月前  发布在  其他
关注(0)|答案(3)|浏览(69)

do是C中的一个关键字,我所看到的是它只能与while一起使用。所以我的问题是,do可以单独使用而不需要while
如果是的话,怎么做?

dm7nw8vv

dm7nw8vv1#

do是do-while循环中使用的关键字。使用do-while循环的一般语法是:do{//Logic }while(condition);

o2g1uqev

o2g1uqev2#

顺便说一句,do语句最常用于提供一些语法糖,并将预处理器宏用作正常的C函数:

#define MY_MACRO_FNC(x) do { whatever(x); } while(0)
/* later in you call this macros as */
MY_MACRO_FNC(x);

字符串

bwitn5fc

bwitn5fc3#

不,它不能。
更准确地说,这是C标准必须说的:

6.8.5迭代语句

iteration-statement:
第一个月
do statement while ( expression ) ;
for ( expressionopt ; expressionopt ; expressionopt ) statement
for ( declaration expressionopt ; expressionopt ) statement

相关问题