Confusion of Boolean data type

sir wrote bollean bit=true;
then he used if loop
if(bit){sys(“hello”);}
else{syso(“bye”)}

and result comes out hello
I am not sure how it came as hello
he was saying the condition if true will print hello else bye
but where did we apply the condition I am nit sure. he only wrote bit in if loop

and next time when he re initialised bit as false then it was printed bye. how ?

is this by default in Boolean data type that if it is initialised as true then it will print output of if loop and if bollaean is initialised as false then it will enter else

the IF statement will run when it is state = true meaning the else part will run when state = false.

if(bit == true) is the same as if(bit)

if(bit == false) is the same as if(!bit)

If you have:

boolean bit = false;

Or

boolean bit;

Then

if(bit)
{

}
else
{
    // This would run!
}
1 Like

mam so if we just code as
boolean bit;
then by default bit will be initialised as false?

yes, …
that’s right

1 Like