pat*_*kku -1 c for-loop nested-loops
我写了一个简单的嵌套For循环,但由于某种原因它永远不会停止.
#include <stdio.h>
int main (void) {
int x,y;
for (x=10;x<100;x+=10) {
for (y=10;y<100;x+=10)
printf("x is %d \n",x);
printf("y is %d \n",y);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我是c的新手,但是从我看过的例子来看,它应该在x和y达到100时停止.但由于某种原因,它会一直持续下去.
小智 6
你需要增加y,而不是x
for (y=10;y<100;y+=10)
Run Code Online (Sandbox Code Playgroud)
而且,看起来你的意思是在内环上放置大括号
for (y=10;y<100;y+=10)
{ // <-- Did you mean to leave this out?
printf("x is %d \n",x);
printf("y is %d \n",y);
} // <-- and this?
Run Code Online (Sandbox Code Playgroud)