Loops

Overview

In the Math in Python lab, we explored the if-elif-else construct, which enabled our programs to make decisions based on conditions. However, the same set of code could be executed only once. In this section, we’ll explore how to make the same set of instructions run multiple times as long as a condition is true – in some cases, forever.

outcomes:

In this lab, you will learn to:

  • Use the while loop control structure.
  • Use error handling in code.

Key terms and descriptions

if..then.else
An if statement is a control structure that allows you to make decisions about your code and branching based on the results.
while loop
A while loop allows us to execute a set of statements as long as the condition is true.
exceptions
Exceptions are a special construct to allow you to test of block of code for errors.