用 Java 繼續宣告
continue 語句用於跳過當前迭代中的剩餘步驟,並從下一個迴圈迭代開始。控制從 continue
語句轉到步驟值(遞增或遞減),如果有的話。
String[] programmers = {"Adrian", "Paul", "John", "Harry"};
//john is not printed out
for (String name : programmers) {
if (name.equals("John"))
continue;
System.out.println(name);
}
continue
語句還可以使程式的控制權轉移到命名迴圈的步長值(如果有):
Outer: // The name of the outermost loop is kept here as 'Outer'
for(int i = 0; i < 5; )
{
for(int j = 0; j < 5; j++)
{
continue Outer;
}
}