The function of the continue statement is to end the current loop and enter the next loop. That is, only this loop ends, not all loops end, and subsequent loops still proceed. The continue statement can only be used in loop statements.
In Java language, the continue statement is used to end the current loop and enter the next loop. That is, only this loop ends, not all loops end. , the subsequent loop still proceeds.
(Recommended tutorial: java entry program)
Let’s take a look at an example:
public class Continue { public static void main(String[] args) { int count = 0; for(int i = 1; i <= 10; i++) { if(i == 5) { // 遍历到5的时候,就会跳过当前循环体,当然也不会去执行剩下的语句了。 // 于是就到了下一轮循环(此时i的值是6),所以这里的第5次输出是6而非5,因为5的那一轮循环被跳过了。 continue; } count++; System.out.println("第" + count + "次输出,输出值为" + i); } } }
(Recommended video tutorial: java video Tutorial)
Output result:
The above is the detailed content of What is the function of continue statement. For more information, please follow other related articles on the PHP Chinese website!