Skip to main content
edited body
Source Link
Michel Keijzers
  • 13k
  • 7
  • 42
  • 59

The official reference can be found here

It is best to always use true and false, and not use numbers.

Below some examples are given

Assign false resp true to a Boolean:

bool a = true;
bool b = false;

Check the Boolean value:

if (b)
{
   // Executed when b is true
}
else
{
   // Executed when b is false
}

if (a && b)
{
   // Executed when a is true and b is true
}

if (a || b)
{
   // Executed when a is true or b is true
}

If b is false, a will be false, otherwise a will stay as it was

a &= b;

If b is true, a will be true, otherwise a will stay as it was

a |= b;

// If a is true it will be false and vice versa.

a = ~a;!a;

The official reference can be found here

It is best to always use true and false, and not use numbers.

Below some examples are given

Assign false resp true to a Boolean:

bool a = true;
bool b = false;

Check the Boolean value:

if (b)
{
   // Executed when b is true
}
else
{
   // Executed when b is false
}

if (a && b)
{
   // Executed when a is true and b is true
}

if (a || b)
{
   // Executed when a is true or b is true
}

If b is false, a will be false, otherwise a will stay as it was

a &= b;

If b is true, a will be true, otherwise a will stay as it was

a |= b;

// If a is true it will be false and vice versa.

a = ~a;

The official reference can be found here

It is best to always use true and false, and not use numbers.

Below some examples are given

Assign false resp true to a Boolean:

bool a = true;
bool b = false;

Check the Boolean value:

if (b)
{
   // Executed when b is true
}
else
{
   // Executed when b is false
}

if (a && b)
{
   // Executed when a is true and b is true
}

if (a || b)
{
   // Executed when a is true or b is true
}

If b is false, a will be false, otherwise a will stay as it was

a &= b;

If b is true, a will be true, otherwise a will stay as it was

a |= b;

// If a is true it will be false and vice versa.

a = !a;
Source Link
Michel Keijzers
  • 13k
  • 7
  • 42
  • 59

The official reference can be found here

It is best to always use true and false, and not use numbers.

Below some examples are given

Assign false resp true to a Boolean:

bool a = true;
bool b = false;

Check the Boolean value:

if (b)
{
   // Executed when b is true
}
else
{
   // Executed when b is false
}

if (a && b)
{
   // Executed when a is true and b is true
}

if (a || b)
{
   // Executed when a is true or b is true
}

If b is false, a will be false, otherwise a will stay as it was

a &= b;

If b is true, a will be true, otherwise a will stay as it was

a |= b;

// If a is true it will be false and vice versa.

a = ~a;