A but statement
#1

Hi SA-MP Community,

I was thinking if there is a but operator like:
pawn Код:
some function..... > 20 but < 40
Reply
#2

&& should do, if you mean in the english language sense of the word.

But to answer your question, no there is no but operator.

pawn Код:
some function..... > 20 && some function..... < 40
Reply
#3

I want all the values between 20 to 40 included.

&& does'nt work I already tried that.
Reply
#4

It does work.

pawn Код:
new var = 25;

if( var > 19 && var < 41 )
{
    //this will be executed if var is between 20 and 40
}
Reply
#5

&& should work.
pawn Код:
if (value >= 20 && value <= 40) { printf("works, %d", value); } else { printf("failed, %d", value);  }
Basically saying if the value is greater than or equal to 20 AND less than or equal to 40 execute code. else return false
Reply
#6

Quote:
Originally Posted by iggy1
Посмотреть сообщение
&& should do, if you mean in the english language sense of the word.

But to answer your question, no there is no but operator.

pawn Код:
some function..... > 20 && some function..... < 40
Indeed, you should use && ( and ) and || ( or ).

Like:
pawn Код:
new functiona, functionb;

if(!strcmp(cmdtext, "/function", true))
    {
    new string[110];
    functiona = random(10);
    functionb = random(10);
    // If function a is 8 or higher and function b is 8 or lower.
    if(functiona >= 8 && functionb <= 8)
        {
        format(string, sizeof(string), ">  'Functiona' = '%d' and 'functionb' = '%d'", functiona, functionb);
        SendClientMessage(playerid, 0xFFFFFFFF, string);
        }
    // If function a is lower then 8 or if functionb if higher then 8.
    else if(functiona < 8 || functionb > 8)
        {
        format(string, sizeof(string), ">  'Functiona' = '%d' and 'functionb' = '%d'", functiona, functionb);
        SendClientMessage(playerid, 0xFFFFFFFF, string);
        }
    }
It's a useless code, but it should explain how to use it.

Best regards,
Jesse
Reply
#7

pawn Код:
switch(var)
{
    case 20 .. 40:
    {
        //this will also be executed if var is between 20 and 40
    }
}
Reply
#8

LOL I did not read further I was doing it last night like this:
pawn Код:
some function.... > 20 && < 40
I will try your one.
Reply
#9

Yeah it works thanks all +rep to all.
Reply
#10

Don't forget to use <= !!! Currently it means: if some function is 21 or higher and 39 or lower!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)