小编use*_*767的帖子

如果语句内部while循环具有相同的条件

是否有更好的方法通过消除ifC语句中的重复条件来编写以下代码?

while (n < 0) {
   printf("Enter a positive integer: ");
   scanf("%d", &n);

   if (n < 0) {
      printf("Error: please enter a positive integer\n");
   }
}
Run Code Online (Sandbox Code Playgroud)

谢谢.

c if-statement while-loop conditional-statements

0
推荐指数
1
解决办法
128
查看次数