Glossary
Boolean Logical Operators
Symbols (`!`, `&&`, `||`) used to combine or modify boolean expressions, allowing for more complex conditional logic.
Example:
Using *&&* and *||* to check if a player has enough coins AND a specific item, OR if they have a special power-up.
Compound Conditional Statements
A single conditional statement that combines multiple simpler conditions using boolean logical operators to create more concise and readable code.
Example:
Instead of nested if statements, you can use if (age >= 18 *&&* hasID) to check two conditions for entry at once.
Indentation
The practice of using spaces or tabs to visually structure code, especially within conditional blocks, to improve readability and clarify code hierarchy.
Example:
Proper indentation makes it easy to see that the return true; statement is executed only if both the outer and inner if conditions are met.
Nested Conditionals
An `if` statement placed inside another `if` statement, where the inner condition is only evaluated if the outer condition is true.
Example:
To determine if a user is an adult and has premium access, you might use an outer if for age and an inner if for premium access.
Order of Operations (Boolean)
The specific sequence in which boolean logical operators are evaluated in an expression: `!` (NOT) first, then `&&` (AND), and finally `||` (OR).
Example:
In !isRaining && hasUmbrella || hasCoat, *!isRaining* is evaluated first, then the *&&* with hasUmbrella, and finally the *||* with hasCoat.
`!` (NOT)
A boolean logical operator that reverses the truth value of a boolean expression; `true` becomes `false`, and `false` becomes `true`.
Example:
If isDaylight is true, then *!isDaylight* evaluates to false, meaning it's night.
`&&` (AND)
A boolean logical operator that returns `true` only if both of the conditions it connects are `true`.
Example:
The expression (score >= 70 *&&* attendance >= 80) is true only if a student passes both criteria.
`||` (OR)
A boolean logical operator that returns `true` if at least one of the conditions it connects is `true`.
Example:
The expression (isWeekend *||* isHoliday) is true if it's either a weekend day or a holiday, allowing for a day off.