From the course: Learning Python (2021)
Unlock the full course today
Join today to access over 24,900 courses taught by industry experts.
Loops - Python Tutorial
From the course: Learning Python (2021)
Loops
- [Instructor] Running a block of code over and over again, via a construct known as a loop is also a very common scenario in programming and Python provides a couple of ways of doing that, which we're going to take a look at now. So in the editor, let's go ahead and open up loops underscore start, and you can see here, I've got a function called main and a variable named X, which I'm initializing to zero. So let's start by taking a look at the while loop. So I'm going to write the while statement and then inside parentheses, I'm going to write X is less than five, and then I'll have a colon which defines the scope block of my while statement. I'm going to print X and then I'm going to have X become equal to X plus one, all right? So once again, you can see that the code in the while loop is indented to indicate that it belongs to the scope of the loop. A while loop executes a block of code while a particular…
Contents
-
-
-
-
Building Hello World9m 5s
-
(Locked)
Variables and expressions11m 44s
-
(Locked)
Python functions11m 52s
-
(Locked)
Conditional structures8m 17s
-
(Locked)
Loops9m 28s
-
(Locked)
Classes10m 30s
-
(Locked)
Importing and using modules2m 22s
-
(Locked)
Using exceptions5m 10s
-
(Locked)
Solution: Palindromes2m 37s
-
-
-
-
-