If you want the same result I guess the first one.
For different results use the switch :x
|
Is it having an if statement looking like this:
or is it having a switch and an if statement?Code:if (alldis || alldat || nevermind || goodluck || pokemon) { }
Whats more efficient of the two?Code:switch (lele) { case alldis: break; case alldat: break; case nevermind: break; case goodluck: break; } if (pokemon) { }
If you want the same result I guess the first one.
For different results use the switch :x
Honestly it depends on personal preference. I've never really noticed any increase or decrease in efficiency on either. Although with switches - you could use 'em like...
So I guess I'd choose switch for what you want to do...but that's just me.Code:public boolean checkCrap(int crap) { switch(crap) { case 0: case 1: case 2: return true; default: return false; } }
You forgot your breaks.Code:public boolean checkCrap(int crap) { switch(crap) { case 0: case 1: case 2: return true; break; default: return false; break; } }
Oh, ok, I thought you did.
Can't remember where I saw this.For a lot of different results, use a switch. For a few (up to 10) different results, use if-then-else statements.
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |