【发布时间】:2019-05-16 09:57:11
【问题描述】:
我需要彻底跳出 while 循环(空检查)并进入外部 for 循环的下一次迭代。
我试过放
for(Product: product:ListofProducts){
while(null!=product.getDate){
if(product.getDate>specifiedDate){
doOnething()
}
else{
doAnotherThing()
}
continue;
}
如果产品日期不为 null 并且它执行 onething() 或 anotherthing() ,那么我想进入 for 循环的下一次迭代
【问题讨论】:
-
将 product.getDate() 设置为 null
-
使用“break”命令
-
你可以标记你的 for 循环
nameofloop: for(Product: product:ListofProducts){..}然后continue nameofloop; -
您在任何情况下都在继续
while循环,这是需要的吗?在这种情况下,我真的不知道while循环的必要性,无论如何......你为什么要使用它? -
可以用if代替while,是不是期望不一样?
标签: java for-loop while-loop