two parents in a conditional
#1

What does two parentheses mean on a conditional? like
Код:
if(! (3 <= strlen( inputtext ) <= 20))
Код:
if( (pInfo[i][AdminLevel] > pInfo[playerid][AdminLevel] ) && (pInfo[i][AdminLevel] >= 2) && (i != playerid)
Reply
#2

Quote:
Originally Posted by Electrifying
Посмотреть сообщение
What does two parentheses mean on a conditional? like
Код:
if(! (3 <= strlen( inputtext ) <= 20))
Код:
if( (pInfo[i][AdminLevel] > pInfo[playerid][AdminLevel] ) && (pInfo[i][AdminLevel] >= 2) && (i != playerid)
There is a specific order in which they are processed.

Very similar to this:

Код:
5 + 6 * 7 = 47
is not the same as

Код:
(5 + 6) * 7 = 77
The same can be said about conditions. Some expressions are meant to be concatenated.

Код:
if(3 <= strlen( inputtext ) <= 20)
will check if strlen(inputtext) is greater than or equal to 3 and smaller than or equal to 20.

With the additional brackets and the exclamation mark, this will negate the outcome of this check. So this:

Код:
if(! (3 <= strlen( inputtext ) <= 20))
will check if strlen(inputtext) is NOT in the specified range.

Same for expressions where AND and OR are used at the same time, there is a specific order and when it's not respected the outcome will be totally different.

So this:

Код:
if(var1 == 3 && var2 == 4 || var == 4 && var2 == 3)
is very different from this:

Код:
if((var1 == 3 && var2 == 4) || (var == 4 && var2 == 3))
The first one will not accept any values, as the check will fail at the second AND.

The second code will accept 3 & 4 OR 4 & 3 respectively.
Reply
#3

Quote:
Originally Posted by NaS
Посмотреть сообщение
There is a specific order in which they are processed.

Very similar to this:

Код:
5 + 6 * 7 = 47
is not the same as

Код:
(5 + 6) * 7 = 77
The same can be said about conditions. Some expressions are meant to be concatenated.

Код:
if(3 <= strlen( inputtext ) <= 20)
will check if strlen(inputtext) is greater than or equal to 3 and smaller than or equal to 20.

With the additional brackets and the exclamation mark, this will negate the outcome of this check. So this:

Код:
if(! (3 <= strlen( inputtext ) <= 20))
will check if strlen(inputtext) is NOT in the specified range.

Same for expressions where AND and OR are used at the same time, there is a specific order and when it's not respected the outcome will be totally different.

So this:

Код:
if(var1 == 3 && var2 == 4 || var == 4 && var2 == 3)
is very different from this:

Код:
if((var1 == 3 && var2 == 4) || (var == 4 && var2 == 3))
The first one will not accept any values, as the check will fail at the second AND.

The second code will accept 3 & 4 OR 4 & 3 respectively.
Thanks!!
Reply
#4

Well thread title look cool anyways
Reply
#5

lmao I thought your parents were in conditional sentence
Reply
#6

Quote:
Originally Posted by TheToretto
Посмотреть сообщение
lmao I thought your parents were in conditional sentence
hahaha I noticed, sorry I don't speak english
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)