Teach Me Python #7: Control Statements Pt.2: While Loops

About: This project has expired.

Welcome to the second part of the control loops tutorial. I am sorry about the recent lack of uploads but I have been fairly busy but here it is at last I hope you enjoy. Today we will be going over while statements and as always please rate and subscribe

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: The Code

How while loops work is that they repeat something while a condition evaluates to true
Type the following code into python

i = 0
while i < 11:
i = i + 1

If you run this code you should notice that it outputs the numbers 1 to 10 then the program ends. This is because it is being told that i equals 0 then on the next line it says 'execute the block of code below while i is below 10' on the next line it is increasing i by 1 then finally it prints it's new value

What if you wanted to loop a certain part of code for ever well you can do this by typing

while True:
#your code here

If you do this but want it to end if something happens you can use a break statement which is simply used by typing break where you want the code to stop looping



  • Indoor Lighting Contest

    Indoor Lighting Contest
  • Make It Fly Challenge

    Make It Fly Challenge
  • Growing Beyond Earth Maker Contest

    Growing Beyond Earth Maker Contest