SA-MP Forums Archive
[If Statement] Comparing value to multiple integers - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: [If Statement] Comparing value to multiple integers (/showthread.php?tid=611595)



[If Statement] Comparing value to multiple integers - Jonesy96 - 08.07.2016

Hi all,

I want to compare a variable against a lot of different integers. I tried the following, expecting it to fail and it did. However, it should give you an idea of what I'm trying to do:

Код:
if(myVariable != 1 && 2 && 8 && 12 && 13 && 14 && 15){
How do I actually do this, with out having 'myVariable' in the if statement a million times over?

Thanks


Re: [If Statement] Comparing value to multiple integers - SickAttack - 08.07.2016

You can't.


Re: [If Statement] Comparing value to multiple integers - AbyssMorgan - 08.07.2016

PHP код:
switch(myVariable)
    case 
12812131415: {}
    default: {
        
//bla bla
    
}




Re: [If Statement] Comparing value to multiple integers - Ritzy2K - 08.07.2016

Or if you really want to use if-else, and also want to compare strings or multiple variables then don't move to switch.

It should be something like this -

Код:
if(YourVariable != 1 && YourVariable != 1) // goes on.



Re: [If Statement] Comparing value to multiple integers - Jonesy96 - 08.07.2016

Quote:
Originally Posted by AbyssMorgan
Посмотреть сообщение
PHP код:
switch(myVariable)
    case 
12812131415: {}
    default: {
        
//bla bla
    
}

Thanks, good idea.

Quote:
Originally Posted by [ND]xXZeusXx.
Посмотреть сообщение
Or if you really want to use if-else, and also want to compare strings or multiple variables then don't move to switch.

It should be something like this -

Код:
if(YourVariable != 1 && YourVariable != 1) // goes on.
Thanks, but this is the point of my question, and what I want to avoid.