Lesson 2.3 — IF Inside Other Things
IF doesn't just stand alone. It can be a piece inside bigger sentences, combined with AND, OR, NOT.
The Setup
So far you've seen IF on its own. But IF is a piece, just like AND, OR, NOT. It can show up inside bigger sentences.
"IF I do my homework, I get screen time. AND IF I get screen time, I can stay up late."
Two IFs, joined by an AND. Each IF promises one thing; the AND requires both promises to hold at once.
Reading Nested IFs
The procedure is the same as Lesson 2.1's: evaluate the innermost piece first, then work outward. Each IF inside the sentence gives you a TRUE or FALSE. Then combine those with whatever connective wraps them.
Suppose you have:
(IF A THEN B) AND (IF B THEN C)
Step 1: figure out the first IF's truth value (based on A and B).
Step 2: figure out the second IF's truth value (based on B and C).
Step 3: AND them together.
That's it. IF doesn't add a new procedure — it just adds one more piece-type to the evaluation. The widget below shows the steps explicitly.
The chain only holds if both promises stayed intact. If you did the homework but didn't get screen time, the first promise was broken — the whole thing is FALSE. If you got screen time but didn't stay up late, the second promise was broken. The reasoning is the same as Lesson 2.1; IFs are just one more piece on the board.
IF With NOT — the Key Flip
One special move shows up often enough to be worth memorizing:
Why? An IF statement is FALSE in exactly one row of its truth table: when X is TRUE and Y is FALSE. Saying "the IF is NOT true" is just another way to say "we're sitting in that one row." So NOT (IF X THEN Y) is exactly the same as X AND (NOT Y).
Here's the truth table to confirm:
| X | Y | IF X THEN Y | NOT (IF X THEN Y) | X AND (NOT Y) |
|---|---|---|---|---|
| T | T | T | F | F |
| T | F | F | T | T |
| F | T | T | F | F |
| F | F | T | F | F |
The two right-hand columns match in every row. That's the equivalence.
Practical use: when you want to contradict a promise — show that it's not been kept — you have to demonstrate that the promised setup happened (X is TRUE) AND the promised result didn't (NOT Y). Both. Not just one of them.
A Real Example
Take the screen-time / stay-up-late chain:
(IF homework THEN screen) AND (IF screen THEN stay_up)
Suppose:
- homework = TRUE (I did it)
- screen = TRUE (I got the screen time)
- stay_up = FALSE (Mom said no anyway — broken chain)
Evaluate:
- First IF:
IF TRUE THEN TRUE= TRUE. (Promise kept.) - Second IF:
IF TRUE THEN FALSE= FALSE. (Promise broken.) TRUE AND FALSE= FALSE.
Whole chain: FALSE. One link broke, so the whole chain breaks.
Tricky Bits
1. Chained IFs nest inside each other.
IF A, THEN (IF B, THEN C).
This is one promise wrapping another. "If A happens, here's a further promise: if B happens, C will follow." Read the inner IF as a single value (TRUE or FALSE), and the outer IF wraps that.
"IF you save your money, THEN (IF you wait for a sale, THEN you can afford the game)."
The outer IF triggers a whole inner IF.
2. NOT in front of IF flips it to AND-NOT.
From the section above: NOT (IF X THEN Y) = X AND (NOT Y). This is the only equivalence-flip IF has. Worth remembering.
3. IF can sit inside an OR too.
(IF it rains, then I bring an umbrella) OR (IF it's sunny, then I bring sunglasses)
That's an OR of two IFs. Each IF gives a TRUE or FALSE; the OR requires at least one to be TRUE.
Practice
Facts:
- A = it is raining (TRUE)
- B = the street is wet (TRUE)
- C = the sun is shining (FALSE)
True or false?
(IF A THEN B) AND (IF C THEN A)(IF A THEN C) OR (IF B THEN A)NOT (IF A THEN B)NOT (IF C THEN A)(IF A THEN B) AND (IF B THEN C)
Answers:
- True — first IF: T→T = T. Second IF: F→T = T (vacuous). T AND T = T.
- True — first IF: T→F = F. Second IF: T→T = T. F OR T = T.
- False — IF A then B is TRUE (T→T). NOT TRUE = FALSE.
- False — IF C then A is TRUE (F→T, vacuous). NOT TRUE = FALSE.
- False — first IF: T→T = T. Second IF: T→F = F. T AND F = F.
Recap
- IF is a piece — it can sit inside compounds with AND, OR, NOT.
- Evaluate each IF separately, then combine. Same procedure as Lesson 2.1, just with one more operator.
NOT (IF X THEN Y) = X AND (NOT Y). The only way to contradict a promise: setup happened, result didn't.- IFs can nest inside other IFs ("if A, then (if B, then C)") — read the inner IF as a single value, the outer IF wraps it.
Disclosure: This page was generated by Claude (Anthropic) under Bill's direction. Bill provided the curriculum design and the pedagogical thread; Claude wrote the prose and built the interactive widget.