+ 16
if condition in if() statement evaluates to true then only if() block executes. if(true){ //statement(s) in this block will execute } if(false){ //statement(s) in this block will NOT execute }
8th Jul 2019, 9:18 PM
Gaurav Agrawal
+ 13
!true means false, !(NOT) operator changes true to false & false to true. thatswhy else block get executed & value of x becomes 2
8th Jul 2019, 9:02 PM
Gaurav Agrawal
+ 3
You are not checking if x is false, you are using an if-statement that is always false. If you want to check if x is false, you should use if(x == false) or simply if(!x). In both examples, x would be false and the else block would be executed, making x receive 2 as its new value.
8th Jul 2019, 9:33 PM
AT-Low
AT-Low - avatar
8th Jul 2019, 10:35 PM
\•/
\•/ - avatar
+ 1
😄
9th Jul 2019, 12:29 PM
\•/
\•/ - avatar