Upon completion of this unit, students will be able to: Identify and use control structures Identify logical and relational operators, how they work, and order of precedence Distinguish the relationship of relational operators and simple data types Identify how to form and evaluate logical (Boolean) expressions Use one-way and/or two-way selection syntax Utilize pseudocode to develop, test, and debug a program Demonstrate a switch statement in a program Identify how to avoid bugs Use the assert function to terminate a program <` | Greater than | `7 > 3` | `true` |
| `<` | Less than | `2 =` | Greater than or equal | `4 >= 4` | `true` |
| `<=` | Less than or equal | `6 0 && y > 0)` | true if both > 0 |
| `||` | OR (true if at least one is true) | `(x > 0 || y > 0)` | true if either > 0 |
| `!` | NOT (reverses truth) | `!(x > 0)` | true if `x <= 0` |
**Order of Precedence (highest → lowest):**
1. `()` parentheses
2. `!` NOT
3. `* / %` (arithmetic)
4. `+ -` (arithmetic)
5. `< >=` (relational)
6. `== !=` (equality)
7. `&&` (AND)
8. `||` (OR)
—
## 3. **Selection Structures**
### One-way (if statement)
“`cpp
if (condition) {
// code executes if condition is true
}
“`
### Two-way (if–else statement)
“`cpp
if (condition) {
// executes if true
} else {
// executes if false
}
“`
—
## 4. **Switch Statement**
– Used when testing a variable against many values (works with integers, chars, enums).
“`cpp
switch (choice) {
case 1:
cout << "Option 1n";
break;
case 2:
cout << "Option 2n";
break;
default:
cout <= 18 THEN
PRINT “Adult”
ELSE
PRINT “Minor”
END IF
“`
—
## 6. **Debugging / Avoiding Bugs**
– Use meaningful variable names
– Test each logic path (`if`, `else`)
– Step through code with a debugger
– Check boundary values (e.g., `0`, negatives, max int)
—
## 7. **Assert Function**
– Terminates program if condition is false.
– Include “ header.
“`cpp
#include
int main() {
int x = 5;
assert(x > 0); // Program continues
assert(x < 0); // Program terminates here
}
“`
—
👉 This sheet gives you **syntax + function definitions** for every concept listed in your unit.
Want me to add **tiny runnable code samples** for each section so you can test them line by line in your compiler?