遇到continue,直接忽略当前的,直接进入下一个循环
Main.java
---------------------------------------------------------------------------------------------------------------------------------
package test010;
public class Main {
public static void main(String[] args) {
int[] array = { 1, 2, 3, 4, 5 };
int total = 0;
for (int i : array) {
if (i % 2 == 0)
continue;
total += i;
}
System.out.println(total);
}
}
before | after | |
total | i | total |
0 | 1 | 0+1 |
1 | 2 | 1 |
1 | 3 | 1+3 |
4 | 4 | 4 |
4 | 5 | 4+5 |