The expression of If statement needs to evaluate to true then and then only body of if statement gets executed. Read here --->
The if-then Statement
In below example value of flag is false means expression of If evaluated to false so
body of If statement i.e. code within { } is not executed which contains print statement
In below code we have
! (NOT) operator with flag which is nothing but !false, in simple english NOT false means true so expression evaluates to true then body of if statement get executed which prints value of flag.