From the course: Introduction to Python: Learn How to Program Today with Python by Pearson
Unlock this course with a free trial
Join today to access over 25,400 courses taught by industry experts.
Use a "while" loop - Python Tutorial
From the course: Introduction to Python: Learn How to Program Today with Python by Pearson
Use a "while" loop
It's finally time to start looking at looping, which is a classic programming concept and controlling the flow, so you don't have to repeat yourself over and over again. The first loop we're going to talk about is while loops. This is one of the ones that's a bit easier to grab your head around when you're a beginner developer. Basically, you're going to just keep looping until a certain condition is met or until you're told to stop. The way it works in Python is, let's just go straight into working in the example file, so I don't have to deal with multi-line code in the REPL. So you can use the while keyword. And there's going to be a condition here. For now, we can just use while true. We'll loop. I can print something and print hi. Now, if I run this, it is going to just print hi forever. And it just keeps printing to the console until I stop it. And that is a totally valid thing to do. You might have a program that you want it to keep running until the user manually stops it. And…
Contents
-
-
-
-
-
-
(Locked)
Learning objectives58s
-
(Locked)
Use a "while" loop11m 22s
-
(Locked)
Improve the number-guessing game with "while" loops7m 44s
-
(Locked)
Create and manipulate lists12m 55s
-
(Locked)
Loop over sequences with "for" loops20m 27s
-
(Locked)
Write a quiz game17m 37s
-
(Locked)
More context: Refactor your code21m 6s
-
(Locked)
-
-
-
-