有人可以告诉我为什么我没有得到这个代码贯穿for循环并通过每个循环增加变量i.我只是打印到程序软件上.
int i;
for(i = 0; i < 100; i++) {
switch(i) {
case 1:
case 2:
case 3:
case 4:
printf("x");
break;
case 0:
printf("y");
return 0;
break;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
你return 0在第一个循环执行case 0:这是一个错字或你打算中止某事吗?
int i;
for(i = 0; i < 100; i++) {
switch(i) {
case 1:
case 2:
case 3:
case 4:
printf("x");
break;
case 0:
printf("y");
return 0; //<----- RETURN exits the function call.
break;
}
return 0; //<-- and if it didn't exit before it will definitely exit here.
}
Run Code Online (Sandbox Code Playgroud)