用 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;
}
}