Well, it isn't nested, but it will still work the same way. That's because
- If
numberHands > 1
then it's by definition > 0
as well.
- If
numberHands > 2
then it's by definition > 1
and > 0
as well.
The proper syntax of a nested if statements would be
if (condition) {
doSomething();
if (anotherCondition) {
doSomethingElse();
if (aThirdCondition) {
doSomethingDifferent();
}
}
}
In your case, you have several, separate if statements, which are not related to one another, aside for the fact that if one is true, all others behind it are true as well.
If you did not intend for all of them to run if numberHands
is equal to 3 , then a switch/case
structure is more suitable, and more readable: OP clarified that he did intend for all of them to run.
switch (numberHands) {
case 1:
wonOrLost(h1.cards, h1);
break;
case 2:
wonOrLost(h2.cards, h2);
break;
case 3:
wonOrLost(h3.cards, h3);
break;
}