Raised This Month: $ Target: $400
 0% 

!! operator


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 03-28-2017 , 12:32   Re: !! operator
Reply With Quote #1

It's not a single operator, but negation operator "!" being done twice. You would want to use that when you want to coerce a cell into a boolean, following the rule that 0 = false, anything else = true.
Code:
!!(0) == false
!!(1) == true
!!(42) == true
!!(-69) == true
This way you are making sure that your boolean is either "true" or "false" and not bool:420 for example. That's good because some people prefer to do "if(variable == true)" instead of "if(variable)", which won't give correct results if you don't "normalize" your boolean value.

Last edited by klippy; 03-28-2017 at 12:56.
klippy is offline
Kotoamatsukami
Member
Join Date: Jan 2017
Location: Malaysia
Old 03-30-2017 , 06:02   Re: !! operator
Reply With Quote #2

Quote:
Originally Posted by KliPPy View Post
It's not a single operator, but negation operator "!" being done twice. You would want to use that when you want to coerce a cell into a boolean, following the rule that 0 = false, anything else = true.
Code:
!!(0) == false
!!(1) == true
!!(42) == true
!!(-69) == true
This way you are making sure that your boolean is either "true" or "false" and not bool:420 for example. That's good because some people prefer to do "if(variable == true)" instead of "if(variable)", which won't give correct results if you don't "normalize" your boolean value.
Pardon me.
Based on your explanation, what I understand is;
PHP Code:
new i_Variable 0

if( !!i_Variable 
That will not let the 'if' statement functional, right? So if we do;
PHP Code:
new i_Variable 1

if( !!i_Variable 
Then, this will make the 'if' statement functional. Well, it is not all time should be storing '1' even other than '1' is still available, as long as the variable did not store '0'.

Correct me if I am wrong.
Thank you.
Kotoamatsukami is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 17:49.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode