Hi all,
very quick query ... which is better to use? If statement, followed by another if statement or if statement followed by if else.
I tried it out with my animation and both appear to do the same thing. What are your views?
Example 1: just if statements
Example 2: if, else if
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | public void animateCoin() { if (AnimationCounter <= 8 ) { setImage(Coin1); AnimationCounter++; } if (AnimationCounter > 9 && AnimationCounter <= 20 ) { setImage(Coin2); AnimationCounter++; } if (AnimationCounter > 21 && AnimationCounter <= 32 ) { setImage(Coin3); AnimationCounter++; } if (AnimationCounter > 33 && AnimationCounter <= 44 ) { setImage(Coin2); AnimationCounter++; } if (AnimationCounter > 45 && AnimationCounter <= 56 ) { setImage(Coin1); AnimationCounter++; } if (AnimationCounter >= 57 ) { AnimationCounter = 0 ; } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | public void animateCoin() { if (AnimationCounter <= 8 ) { setImage(Coin1); AnimationCounter++; } else if (AnimationCounter > 9 && AnimationCounter <= 20 ) { setImage(Coin2); AnimationCounter++; } else if (AnimationCounter > 21 && AnimationCounter <= 32 ) { setImage(Coin3); AnimationCounter++; } else if (AnimationCounter > 33 && AnimationCounter <= 44 ) { setImage(Coin2); AnimationCounter++; } else if (AnimationCounter > 45 && AnimationCounter <= 56 ) { setImage(Coin1); AnimationCounter++; } else if (AnimationCounter >= 57 ) { AnimationCounter = 0 ; } } |