c语言 开发语言 C primer plus 6.8 出口条件循环: do while - please enter the secret code number:12

📅 2026-11-30 👤 拼多多助力营销技巧 📂 2026拼多多助力 👁️ 137 次阅读

while和for都是入口条件循环,即在循环的每次迭代之前检查测试条件,所以有可能根本不执行循环体中的内容。C语言还有出口条件循环,即在循环每次迭代之后检查测试条件,这保证了至少执行循环体中的内容一次。这种循环叫 do while 循环。

do while 循环

下面是do while 循环的通用语句:

do

statement

while (expression);

一般注解;

do while 语句创建一个循环,在expression为假或0之前重复执行循环体的内容,do while 语句是一种出口条件循环,即在执行完循环体后才根据测试条件决定是否再次执行循环。所以该循环至少执行一次。

其中,statement可以是一条简单语句或复杂语句。

注意:do while 循环以分号结尾

#include

int main(void)

{

conset int secret_code = 13;

int code_entered;

do

{

printf("To enter the triskaidekaphobia therapy club,\n");

printf("please enter the secret code number:");

scanf("%d",&code_entered);

}while (code_entered != secret_code);

printf("Congratulations!You are cured!\n");

return 0;

}

输出结果如下:

To enter the triskaidekaphobia therapy club, 拼多多帮助力入口

please enter the secret code number:12

To enter the triskaidekaphobia therapy club,

please enter the secret code number:13

Congratulations!You are cured!

推荐阅读

标签: 拼多多助力网站平台 赚钱项目 拼多多助力网 首码项目 手赚APP
拼多多助力营销技巧