删除下面 C++ 代码中的 continue 后,其输出与原来相同。
int x = 0;
while (x < 4) {
x++;
if (x == 2) continue;
cout << x << ",";
}
正确答案:错误(×)
int x = 0;
while (x < 4) {
x++;
if (x == 2) continue;
cout << x << ",";
}
正确答案:错误(×)
continue 跳过本次输出,结果是 1,3,4,;删掉 continue 后 x=2 也会输出,变成 1,2,3,4,,两者不同,选 ×。💡 continue 的作用就是跳过本轮剩余语句,删掉会改变输出。想系统刷完 GESP C++ 1~8 级真题,并查看每道题的逐题精讲?
进入 GESPPASS 开始练习