Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Android / If vs. nested case

Author
Message
Saphaa
9
Years of Service
User Offline
Joined: 22nd Jul 2014
Location:
Posted: 22nd Jul 2014 05:21
Sorry about the noob question I'm very new to programming
Any ideas which android would handle better.

64 if statements needing to be run every time 2 sprites collide

vs.

a 8 case statement select option
with another 8 cases for each
whenever two sprites collide?

I can code it either way, I'm just unsure how each effect performance.

learning to code 1 debug message at a time
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 22nd Jul 2014 22:01
Definitely go with case statement.

It allows you to organize the logic better, is easier to read and easier to debug.

Also, at runtime, it knows which case to go to without having to go through lots of 'if' checks.

Cheers,
Ancient Lady
Saphaa
9
Years of Service
User Offline
Joined: 22nd Jul 2014
Location:
Posted: 25th Jul 2014 02:59
sweet kk thank you. I'm trying to keep things running as smoothly as possible.

learning to code 1 debug message at a time
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 26th Jul 2014 04:35
You are totally welcome.

Another benifit of case vs if-else is that you can more easily add new cases.

Happy Programming!

Cheers,
Ancient Lady

Login to post a reply

Server time is: 2024-03-28 19:26:10
Your offset time is: 2024-03-28 19:26:10