Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Write a Compound Condition

From Groundhog Learning

Create a compound condition combining multiple simple conditions using logical operators to decide program behavior.

Write a Compound Condition in C#

AND (C#)

💻 C#

bool hasEnoughMoney = true;
bool hasInventorySpace = true;

if(hasEnoughMoney && hasInventorySpace) // true if both conditions are true
{
    // Player can buy the item.
}

OR (C#)

💻 C#

bool hasShield = true;
bool isInvincible = false;

if(hasShield || isInvincible) // true if either condition is true
{
    // Player don't take damage.
}

NOT (C#)

💻 C#

bool doorIsLocked = true;

if(!doorIsLocked) // true if condition is false
{
    // Player can enter.
}

Related Concepts