【C/C++】while与do...while
当需要在每次输入前给提示时,do while循环好于while循环
const int secret_code = 13;
int code_entered;
pritnf("To enter the treskaidekaphobia therapy club,\n");
printf("please enter the secret code number:");
scanf("%d", &code_entered);
while ( code_entered != secret_code )
{
pritnf("To enter the treskaidekaphobia therapy club,\n");
printf("please enter the secret code number:");
scanf("%d", &code_entered);
}
printf("Congratuations! You are cured!\n");
const int secret_code = 13;
int code_entered;
do
{
pritnf("To enter the treskaidekaphobia therapy club,\n");
printf("please enter the secret code number:");
scanf("%d", &code_entered);
} while ( code_entered != secret_code );
printf("Congratuations! You are cured!\n");