Loops

Loops are a kind of control flow, but they rerun the same block of code over and over again until something else tells the loop to stop repeating itself. This is a bit different from conditional statements since these only run the block of code once. The two kinds of loop are while and for. Both types of loop are really useful.

while

while is one kind of loop. When we make a while loop, the program repeats itself until a given block of code happens. When programming a while loop, we need to create some rules, or our program will run forever.

For example, we can make this rule: when the calculator is on, perform the following steps:

  1. Run the calculator.
  2. Prompt the user to keep calculating.
  3. When the user hits the else statement, turn the calculator ...

Get Python Projects for Kids now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.