Not always.. If your only comparing a few values then if is the same or better than switch. Sure if you are comparing significant amounts of values then switch is better. But otherwise they are the same.
- Code: Select all
If( value1 == value3) { //do something}
else { //do something else}
is much better than.
- Code: Select all
switch(value1)
case value3: { //do something; break;}
default: { //do something}
especially if what you are comparing isn't just integers.
where as:
- Code: Select all
switch(value1)
case 0: //do this; break;
case 1: //do this; break;
case 2: //do this; break;
case 3: //do this; break;
...
case 100: //do this; break;
is much better than the if code which I don't want to try to write.
It just knowing when to use which.
Honestly, I would avoid a switch in place of a for statement if it got to be too long.
But because we are talking about script here, specifically for gE. We need to look at how gE handles and compiles the script. Because it could treat multiple if statements just like switch statements and compile them exactly the same and treating them in the most efficient matter. Then it would just be a matter of aesthetics.
jimmynewguy wrote:As for the code, it's like this.
- Code: Select all
result = (x > 0);
So we have if x is greater than 0 then return 1, otherwise return 0. In the code I showed hblade I just checked the two ways it could go down and their returns would change the variable. So, if X > 0 then we get 1 for the first and 0 for the second. 1 - 0 = 1 so we add one. If it's X is 0 then they're both 0 and we don't change X and if X < 0 then 0 - 1 = -1 and adding 1 is like subtracting.
I kinda went thorough in case someone else read this and didn't understand either. Makes me feel like I'm "talking down to you" and didn't want that since I can tell you know a lot more about coding than I do with all that iso stuff
Just so you know!
THANK YOU SO MUCH!! I just don't know the math that well, but it makes perfect sense now! I just couldn't figure out how it was returning a value.