Is "if (!bool)" the same as "if (bool == false)" ?

Hello,
The default value of Friend boolean is false. Does !Friend means “Friend == false” or does it means a state that is opposite of current state. Example: Friend default is false so, not friend is opposite of false so “Friend == true”. I always thought !bool means bool==false. But a tutorial I’m learning seems off. So want to know.

public bool Friend = false;     // variable declaration

if (!Friend)
{
do this code
}

Yes! !bool will flip the boolean for example :

public bool enemy = false; // in the example enemy is false
bool friend = !enemy; // NOT false is true so friend is true

In this code friend and enemy will always be the opposite as you can’t be enemies and friends.
_
An if() statement is only asking if the stuff inside the brackets returns true.
as !false is true (similarly !true is false) then “do this code” will occur.
You can actually test out more complex examples yourself:

bool test1 = !(true&&false); // true AND false is false. but !(true AND false) is true.
Debug.Log("test1: " + test1);
bool test2 = (true||false) && !(true&&false); // true OR false is true AND !(true AND false) is true
Debug.Log("test2: " + test2);

it’s good to understand how AND and OR work as when working with more complicated code you will likely use them. A final example assuming the booleans are set elsewhere in the code.

bool friend;
bool enemy;
bool angry;
bool happy; 
bool tired; 

if (angry && (!friend || enemy) && !tired && !happy)
{
   Attack();
}

both!

In this scenario:

/

bool flag = true;
if (!flag)
    {
        Console.WriteLine(!flag);
        Console.WriteLine(flag);
}

/

there is no flipping, it means if(flag == false)

when you assign !flag to something it means you assigning opposite of flag. completely different use of !. “!” has many more uses also.