You are currently viewing this lesson as a guest. Click here to enroll in this class.
Introduction to Control Flow
Completed

Introduction to Control Flow

Imagine writing a program that always executed the same exact instructions every single time it ran. The program never reacted to user input or changed its behavior based on what data it had available. You might be able to write something simple that prints static data, but you won't get meaningfully further than that.

Robust applications need the ability to change their behavior based on inputs and data. One way this is accomplished is through control flow: the logic that dictates the execution path of our program. Control flow comes in a few forms, including loops, conditionals, and control transfer statements.

In this chapter, we'll cover:

  • Iterating over collections with for-in loops
  • Waiting until a condition is met with while loops
  • Pattern matching with the switch statement
  • Interrupting or transferring application flow with control transfer statements
  • Early exit with the guard statement

We covered the if conditional statement in our Basics section here, so feel free to refer back to that lesson for a refresher.

Did you like this lesson?

(Voting helps us personalize your learning experience!)