You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Thinking logically means identifying decision points in a problem, determining the conditions that govern each decision, using logical reasoning to predict outcomes, and applying logic to debug programs. This is a core part of OCR H446 section 2.1.
Logical thinking in Computer Science is about making decisions based on conditions. Every program contains decision points where the flow of execution depends on whether a condition is true or false.
| Concept | Definition |
|---|---|
| Decision point | A place in an algorithm where the next step depends on a condition |
| Condition | A Boolean expression that evaluates to TRUE or FALSE |
| Logical reasoning | Using conditions and rules to determine what will happen |
Decision points appear whenever there is a choice or branch in an algorithm:
| Structure | Decision | Example |
|---|---|---|
| IF-THEN-ELSE | Choose between two paths | IF age >= 18 THEN grant access ELSE deny access |
| WHILE loop | Continue or stop | WHILE password incorrect DO ask again |
| FOR loop | Implicit decision at each iteration | FOR i = 0 TO n-1 (implicitly checks i < n) |
| CASE/SWITCH | Choose among multiple paths | CASE grade OF "A": distinction, "B": merit, etc. |
| Exception handling | Handle error or continue normally | TRY ... CATCH if file not found |
Worked Example — ATM Withdrawal:
1. User inserts card
2. DECISION: Is the card valid? (Yes/No)
3. User enters PIN
4. DECISION: Is the PIN correct? (Yes/No)
5. DECISION: Has the user exceeded maximum attempts? (Yes/No)
6. User selects amount
7. DECISION: Is the amount <= account balance? (Yes/No)
8. DECISION: Does the machine have enough cash? (Yes/No)
9. Dispense cash
10. Update balance
Each DECISION is a decision point with a condition that must be evaluated.
For each decision point, you must specify the exact condition being tested:
| Decision point | Condition | Data type |
|---|---|---|
| User is an adult | age >= 18 | Integer comparison |
| Password is correct | enteredPassword = storedHash | String comparison |
| List is empty | length(list) = 0 | Integer comparison |
| Item exists in database | searchResult != NULL | Null check |
| Temperature is dangerous | temp > 100 OR temp < -20 | Compound Boolean |
Compound conditions use AND, OR, and NOT to combine simple conditions:
| Compound condition | Meaning |
|---|---|
| age >= 18 AND hasID = TRUE | Both must be true |
| isStudent = TRUE OR isStaff = TRUE | At least one must be true |
| NOT(fileExists) | The file must not exist |
| (score >= 40) AND (coursework >= 30) AND (attendance >= 80) | All three must be true to pass |
Logical reasoning allows you to trace through an algorithm and predict the output without running it.
Trace table example:
Given:
x = 5
y = 3
WHILE x > 0
IF x MOD 2 = 1 THEN
y = y + x
ELSE
y = y - 1
END IF
x = x - 1
END WHILE
OUTPUT y
Trace:
| Iteration | x (start) | x MOD 2 = 1? | y (after) | x (after) |
|---|---|---|---|---|
| 1 | 5 | Yes (5 is odd) | 3 + 5 = 8 | 4 |
| 2 | 4 | No (4 is even) | 8 - 1 = 7 | 3 |
| 3 | 3 | Yes (3 is odd) | 7 + 3 = 10 | 2 |
| 4 | 2 | No (2 is even) | 10 - 1 = 9 | 1 |
| 5 | 1 | Yes (1 is odd) | 9 + 1 = 10 | 0 |
x is now 0, so the loop ends. Output: 10.
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.