Bootcamp Curriculum • 5 Modules • 12 Chapters • Multi-Language Runner (Python, JS, Java, C++) • Interactive Memory Trace • AI Mentor
CHAPTER 04 · CONTROL-FLOW5 min read

Conditionals & modulo arithmetic

Programs become intelligent when they can choose different paths based on incoming conditions. Learn how Python evaluates Truthiness and executes conditional branches.

By the end of this chapter, you can:
  • Write conditions that evaluate to True or False.
  • Check even vs odd numbers using the modulo operator (%).
  • Chain multiple decisions using if, elif, and else.
Explanation DepthTailor the level of detail to your learning goal
💻 Standard College Notes

if / elif / else blocks and comparison operators.

Comparison operators: ==, !=, >, <, >=, <=. The modulo operator % is vital for checking parity (e.g. num % 2 == 0 for even numbers). Python uses 4-space indentation to define blocks.

💡Remember: = is assignment, while == is equality comparison.

Checking Even vs Odd with Modulo (%)

The modulo operator (%) returns the remainder of a division. Any number divided by 2 with remainder 0 is even; otherwise, it is odd.

example_1.py
Ctrl + ↵ to run
Terminal Output
Ready to execute
Click "▶ Run Code" or press Ctrl+Enter to compile & run this snippet.

Treasure Island branching logic

Day 3's iconic project: a choose-your-own-adventure game where each decision leads deeper into the island or causes Game Over.

example_2.py
Ctrl + ↵ to run
Terminal Output
Ready to execute
Click "▶ Run Code" or press Ctrl+Enter to compile & run this snippet.
✦ Interactive Dry-Run Visualizer

Control Flow Visualizer: Nested Decision Tree

Follow the execution pointer through nested IF conditions to the win branch.

STEP1 / 6
1direction = "left"👉 Executing
2action = "wait"
3if direction == "left":
4 if action == "wait":
5 outcome = "Win"
6print(outcome)
VariableValue in MemoryData Type
direction"left"str
Initialize direction choice

Player selected 'left'.

Console Stream (stdout)
(No output generated yet)
Line 1: direction = "left"

🔧 Assignment vs Comparison Bug

A condition mistakenly used single = instead of double ==, throwing a SyntaxError.

⚡ +100 XP
fix_bug.pyPython 3.10
⚡ Quick Revision Quiz

Predict The Output (2 Questions)

Question 1 of 2:
What is the result of 15 % 4?
Question 2 of 2:
Which keyword is used for 'else if' in Python?

Your lightbulb moment

✧

The key takeaway
Branching lets code make decisions. In Python, four-space indentation marks which instructions belong to each decision branch.

Make it yours

Try changing choice1 to 'right' and rerun the code to see how the branch skips directly to Game Over.

Try editing the code in the playground above in Python, JavaScript, Java, or C++, and use the step-by-step Dry-Run Table to inspect how variables mutate in memory. If you get stuck, click the 🤖 AI Doubt Solver button on your screen for instant explanations!