Click to See Complete Forum and Search --> : Advice on condtions


florida
01-16-2003, 08:47 AM
I have alot of "this.ID" to work with here. I only listed 3 for each condition for this example.
Anyway to shorten this???

if((this.ID == 1) || (this.ID == 4) || (this.ID == 5))
{
//do stuff
}
else if((this.ID == 12) || (this.ID == 24) || (this.ID == 27))
{
//do stuff
}
else if etc...

gil davis
01-16-2003, 09:05 AM
Look into the SWITCH statement:

switch (this.ID){
case 1 :
case 4 :
case 5 :
// do stuff
break;
case 12 :
case 24 :
case 27 :
// do stuff
break;
...
default : // do stuff if no match;
}

khalidali63
01-16-2003, 09:08 AM
Aand your question is?
:-)

gil davis
01-16-2003, 09:28 AM
Originally posted by khalidali63
Aand your question is?
:-)
Originally posted by florida
Anyway to shorten this???
Perhaps you were too close to the monitor...

florida
01-16-2003, 09:58 AM
i tried doing this and it wont work??

switch (this.ID){
case > 1 && case < 5 :
case != 3 :
// do stuff
break;
case 34 :
case 24 :
case 27 :
// do stuff
break;
...
default : // do stuff if no match;
}

gil davis
01-16-2003, 10:08 AM
i tried doing this and it wont work??

switch (this.ID){
case > 1 && case < 5 :
case != 3 :
And what led you to believe that it would?

It's not supposed to.

khalidali63
01-16-2003, 10:25 AM
Originally posted by gil davis
Perhaps you were too close to the monitor...

lol..I guess you are correct,I better turn the damn thing off for a change..:-)