- Code: Select all
switch(X) {
case>0:
A->x+=X; break;
case<0:
A->x-=X; break; }
switch(Y) {
case>0:
A->y+=Y; break;
case<0:
A->x-=X; break; }
This results in an error
switch(X) {
case>0:
A->x+=X; break;
case<0:
A->x-=X; break; }
switch(Y) {
case>0:
A->y+=Y; break;
case<0:
A->x-=X; break; }
if(x > 0){ //do something)
if else(x < 0) { //do something else}
if(y > 0){ //do something)
if else(y < 0) { //do something else}
A->x += (X > 0) - (X < 0);
A->y += (Y > 0) - (Y < 0);
jimmynewguy wrote:Or if you're using switch just because you "hate" ifs, then you should be able to use:
- Code: Select all
A->x += (X > 0) - (X < 0);
A->y += (Y > 0) - (Y < 0);
result = (x > 0);
If( value1 == value3) { //do something}
else { //do something else}
switch(value1)
case value3: { //do something; break;}
default: { //do something}
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;
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!
EvanBlack wrote: I don't hate ifs, don't understand why people do...
EvanBlack wrote: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.
Fuzzy wrote:Every time you use if a bunny dies.
Jagmaster wrote:This makes sense now. Thank you Game a gogo.Fuzzy wrote:Every time you use if a bunny dies.
(\__/)
(x__x)
(>__<)
Bunny can't dominate the world if you use if's too much.
if(1)
{
--bunnies;
}
Users browsing this forum: No registered users and 1 guest