two parents in a conditional
#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


Messages In This Thread
two parentheses in a conditional - by Electrifying - 28.09.2018, 00:50
Re: two parents in a conditional - by NaS - 28.09.2018, 01:07
Re: two parents in a conditional - by Electrifying - 28.09.2018, 01:11
Re: two parents in a conditional - by v1k1nG - 28.09.2018, 14:09
Re: two parents in a conditional - by TheToretto - 28.09.2018, 14:16
Re: two parents in a conditional - by Electrifying - 28.09.2018, 14:24

Forum Jump:


Users browsing this thread: 1 Guest(s)