条件がtrueと評価された場合、forループの最初のサイクルでのみ条件をチェックし、残りのサイクルでいくつかのコードを実行する方法はありますか?forループとその中に2つの基本的な条件があり、最初のサイクルでのみチェックする必要があります。それらのいずれかが真の場合、他のすべてのサイクルで1つまたは別のコードが実行されています。他のサイクルではこれらの条件を確認できませんが、最初のサイクルは両方とも真であり、必要なものではないためです((
public void someMethod() {
int index;
for (int j = 0; j < 10; j++) {
if (j == 0 && cond1 == true && cond2 == true) {
methodXForTheFirstCycle();// this method will change cond2
methodXForTheRestCycles();// not the right place to put it
} else if (j == 0 && cond1 == true) {// and cond2 == false
methodYForTheFirstCycle();// this method will change cond2
methodYForTheRestCycles();// not the right place to put it
}
}
}