当标准的for循环使用 return时 , return直接跳出循环,终止循环
public static void main(String[] args) {
String[] str = {"1" , "2", "3", "4", "5"};
for (int i=0; i<str.length; i++){
if (StringUtils.equals(str[i],"3")) return;
System.out.println(str[i]); // 1 2
}
}
当标准的for循环使用 continue时 , continue直接跳过本次循环,后面还会接着执行
public static void main(String[] args) {
String[] str = {"1" , "2", "3", "4", "5"};
for (int i=0; i<str.length; i++){
if (StringUtils.equals(str[i],"3")) continue;
System.out.println(str[i]); // 1 2 4 5
}
}