我有一個 for 循環,我想檢查數組中的一些值for (Hero myHeroes : heroes) { if (myHeroes.getCurrentHP() <= 60) { world.castAbility(hero, healerHeal, myHeroes.getCurrentCell()); } else if() { } }如果我想檢查所有內容,我應該怎么做myHeroes HPs,如果它們不低于 60,請檢查 else-if 部分(對不起,如果我的英語不好)
2 回答

ibeautiful
TA貢獻1993條經驗 獲得超6個贊
我想這就是你的意思。
boolean wasAHeroBelowSixtyHp = false;
for (Hero myHeroes : heroes) {
if (myHeroes.getCurrentHP() <= 60) {
world.castAbility(hero, healerHeal, myHeroes.getCurrentCell());
wasAHeroBelowSixtyHp = true;
}
}
if (wasAHeroBelowSixtyHp) {
// do something
}

白衣非少年
TA貢獻1155條經驗 獲得超0個贊
boolean allOver60 = true;
for(Hero myHeroes : heroes)
{
if ( myHeroes.getCurrentHP() <= 60 )
{
world.castAbility( hero, healerHeal, myHeroes.getCurrentCell() );
allOver60 = false;
}
}
if( allOver60 )
{
doSth();
}
添加回答
舉報
0/150
提交
取消