在C语言中,可以使用continue语句来跳过当前循环中剩余的代码,并开始下一次循环。它可以用于for循环、while循环和do-while循环。以下是continue语句的一些使用示例:
for循环中使用continue:for (int i = 0; i < 10; i++) { if (i == 5) { continue; // 跳过剩余的代码并开始下一次循环 } printf("%d ", i); } 输出结果为:0 1 2 3 4 6 7 8 9
while循环中使用continue:int i = 0; while (i < 10) { if (i == 5) { i++; continue; // 跳过剩余的代码并开始下一次循环 } printf("%d ", i); i++; } 输出结果为:0 1 2 3 4 6 7 8 9
do-while循环中使用continue:int i = 0; do { if (i == 5) { i++; continue; // 跳过剩余的代码并开始下一次循环 } printf("%d ", i); i++; } while (i < 10); 输出结果为:0 1 2 3 4 6 7 8 9
需要注意的是,continue语句只会跳过当前循环块中的剩余代码,并不会终止循环。因此,循环条件和循环迭代语句仍然会执行,控制流会回到循环的开始处进行下一次迭代。