Introduction
Computer programs are great at dealing with repetitive tasks. As a developer, you'll often find yourself needing to loop over sequences of values, such as strings, numbers, and objects. Python provides two mechanisms for performing such tasks, which are while
and for
loops.
Scenario: Working with flow control on a planetary app
Imagine you're creating an application where users enter a list of planet names. After the users enter the names, you display the results back to them. This scenario requires prompting the users multiple times to enter values. When they're done, the code displays all the data in the list. In this module, we explore how you can use while
and for
loops to create this application.
By the end of the module, you'll be able to use while
and for
loops.
What are you learning?
After you've completed this module, you can:
- Identify when to use
while
andfor
loops. - Run a task multiple times by using
while
loops. - Loop over list data by using
for
loops.
What is the main objective?
In this module, learn how to apply flow control to your app to repeat statements and work with list structures.
Prerequisites
You should be familiar with the concept of programming.
You don't need to install Python to complete this module. You'll use an interactive sandbox to complete the exercises.
If you want to try out the code in the explanations, you might want to work through Get started with Python in Visual Studio Code first, if you haven't already. This module helps you prepare a Python environment.