c语言中循环控制语句(do语句,限制用户输入数值的范围)
1、
#include <stdio.h>
int main(void)
{
int i;
do
{
puts("please input an integer! the range is 0-2!");
printf("i = "); scanf("%d", &i);
}
while (i < 0 || i > 2); ## 此句判断为非0,则继续执行循环体
switch (i)
{
case 0: puts("you had choose stone!"); break;
case 1: puts("you had choose scissors!"); break;
case 2: puts("you had choose clothes!"); break;
}
return 0;
}