while循环和for循环都是入口条件循环,即在每次循环之前检查测试条件,所以可以不执行内容循环体的全部。C语言还有一个退出条件循环(exit-conditionloop),它在循环的每次迭代后检查测试条件,这保证了循环体的内容至少被执行一次。这种循环称为dowhile循环。请参阅以下示例:#includeintmain(void){constintsecret_code=13;intcode_entered;do{printf("Toenterthetriskaidekaphobiatherapyclub,\n");printf("pleaseenterthesecretcodenumber:");scanf("%d",&code_entered);}while(code_entered!=secret_code);printf("Congratulations!Youarecured!\n");return0;}运行结果:进入triskaidekaphobia治疗俱乐部,请输入暗号:12进入triskaidekaphobia治疗俱乐部,请输入密码:14进入triskaidekaphobia治疗俱乐部,请输入密码:13恭喜!你痊愈了!您也可以使用while循环编写等效程序,但它更长,如程序列表6.16所示。#includeintmain(void){constintsecret_code=13;intcode_entered;printf("Toenterthetriskaidekaphobiatherapyclub,\n");printf("pleaseenterthesecretcodenumber:");scanf("%d",&code_entered);while(code_entered!=secret_code){printf("Toenterthetririskaidekaphobiatherapyclub,\n");printf("pleaseenterthesecretcodenumber:");scanf("%d",&code_entered);}printf("Congratulations!Youarecured!\n");return0;}以下是dowhile循环的一般形式:dostatementwhile(expression);语句可以是简单语句,也可以是复合语句。请注意,do-while循环以分号结束。a=dowhile=loop=do-while循环的结构是在执行完循环体后执行测试条件,所以循环体至少执行一次;for循环或while循环在执行循环体之前执行测试条件。dowhile循环适用于那些至少要迭代一次的循环。例如,以下是包含一个do-while循环的密码程序的伪代码:回答“否”后,“其他行为”部分仍然执行,因为测试条件执行晚了。