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
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; } }
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; } }