Part II: Control Flow

Your programs can now store data and display results. That is genuinely useful --- but it is also limited. A program that runs the same instructions every time, in the same order, no matter what, is like a recipe that cannot adjust for the number of guests. It works, but only in one situation.

Part II changes that. After these three chapters, your programs will be able to think, repeat, and organize.

What This Part Covers

Chapter 4: Conditionals teaches your programs to make decisions. Using if, elif, and else, you will write code that responds differently depending on what it encounters. Is the user's input valid? Is the score a passing grade? Should the game's character go left or right? Boolean logic is the language of decision-making, and once you learn it, you will see it everywhere --- not just in code, but in how you think about everyday problems.

Chapter 5: Loops gives your programs the ability to repeat work. A computer's real superpower is not speed --- it is tirelessness. With for and while loops, you will process lists of data, build menus, accumulate totals, and automate tasks that would take hours by hand. You will also learn to recognize and fix the beginner's nemesis: the infinite loop.

Chapter 6: Functions teaches you to organize your thinking. Instead of writing one long script, you will learn to break problems into small, reusable pieces. Functions are the single most important tool for managing complexity, and they will change how you approach every problem from this point forward. This chapter is the gateway to everything else in the book.

Why This Matters

Control flow is what separates a calculator from a computer. Professionals do not write scripts that only run in one direction. They write programs that adapt, programs that handle thousands of records without a human babysitting them, and programs built from clean, reusable components. These are the skills that make you genuinely useful on day one of any technical role.

What You Will Be Able to Do

By the end of Part II, you will be able to:

  • Write programs that make decisions based on user input and data conditions
  • Process collections of data using loops without writing repetitive code
  • Build interactive, menu-driven programs with input validation
  • Define, call, and compose functions with parameters and return values
  • Trace through function calls on the call stack
  • Apply the principle of single responsibility to keep functions focused

How the Chapters Connect

These chapters build a clear progression. Chapter 4 gives your programs the ability to choose. Chapter 5 gives them the ability to repeat. Chapter 6 gives you the ability to organize choices and repetition into named, reusable building blocks. Together, they represent the core toolkit of procedural programming --- and every chapter from Part III onward depends on what you learn here.

Your Progressive Project: TaskFlow

TaskFlow takes a major leap in Part II. In Chapter 4, you will add task priorities using conditionals and validate user input so bad data does not crash your program (v0.3). In Chapter 5, you will build a menu-driven interface with a while loop that displays all tasks in a numbered list (v0.4). In Chapter 6, you will refactor the growing codebase into clean functions --- add_task(), list_tasks(), delete_task(), and main() --- transforming a tangled script into something you would not be embarrassed to show another programmer (v0.5).

By the end of this part, TaskFlow will feel like a real application. More importantly, you will feel like a real programmer.

Chapters in This Part