-1
我有这样的:从回路断开,当条件为真
for(String s : names){ //names is an ArrayList of strings
if(s.equals("bob")){
//do sth and then break from the loop
break;
}
}
当里面的,如果是真的,我希望for循环打破了条件。但它不......我的代码错了吗?
编辑:
的问题是,我有一个额外的for循环在我的代码
for(//a loop here){
for(String s : names){ //names is an ArrayList of strings
if(s.equals("bob")){
//do sth and then break from the loop
break;
}
}
}
这就是为什么里面loop
被突破后执行...
确定'names'包含' “鲍勃”'字符串? – Eran
你确定它全是小写吗?使用'.equalsIgnoreCase'作为不区分大小写的字符串比较 – Arc676
我投票结束,因为我在代码中有2个循环.. – yaylitzis