do是C中的一个关键字,我所看到的是它只能与while一起使用。所以我的问题是,do可以单独使用而不需要while。如果是的话,怎么做?
do
while
dm7nw8vv1#
do是do-while循环中使用的关键字。使用do-while循环的一般语法是:do{//Logic }while(condition);
o2g1uqev2#
顺便说一句,do语句最常用于提供一些语法糖,并将预处理器宏用作正常的C函数:
#define MY_MACRO_FNC(x) do { whatever(x); } while(0) /* later in you call this macros as */ MY_MACRO_FNC(x);
字符串
bwitn5fc3#
不,它不能。更准确地说,这是C标准必须说的:
iteration-statement:第一个月do statement while ( expression ) ;个for ( expressionopt ; expressionopt ; expressionopt ) statement个for ( declaration expressionopt ; expressionopt ) statement个
do statement while ( expression ) ;
for ( expressionopt ; expressionopt ; expressionopt ) statement
for ( declaration expressionopt ; expressionopt ) statement
3条答案
按热度按时间dm7nw8vv1#
do是do-while循环中使用的关键字。使用do-while循环的一般语法是:do{//Logic }while(condition);
o2g1uqev2#
顺便说一句,do语句最常用于提供一些语法糖,并将预处理器宏用作正常的C函数:
字符串
bwitn5fc3#
不,它不能。
更准确地说,这是C标准必须说的:
6.8.5迭代语句
iteration-statement:
第一个月
do statement while ( expression ) ;
个for ( expressionopt ; expressionopt ; expressionopt ) statement
个for ( declaration expressionopt ; expressionopt ) statement
个