Iterate through code blocks by using the while statement

Beginner
Developer
Visual Studio

Use the while statement and related Python code constructs to add looping logic to your programs.

Learning objectives

In this module, you will:

  • Use the while statement to iterate through a code block.
  • Use the break, continue, and else statements to further control iteration.
  • Use alternate assignment operators to perform mathematical operations that also assign values.

Prerequisites

  • You should have your Python development environment set up, know how to create a working folder and code files, and know how to execute the code in a code file.
  • You should understand data types like str and int and know how to define, set, and get values from a variable.
  • You should understand what a code block is and how to define one.
  • You should understand how to include a module from the Python Standard Library.
  • Experience using if statements and the string's isnumeric() helper method to evaluate user input.