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
- Creates: Compound Condition
- Uses: Logical Operator