Join Joe Marini for an in-depth discussion in this video Loops, part of Learning Python.
Repeating code over and over again via a construct known as a loop is also a fairly…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 let's open up loops_start.py. And you can see I've got a stubbed out…function here called main. And a variable named x which I'm…initializing to zero. Over here in example snippets.…We're going to come down to the loop section.…And let's start by copying lines 105 through 108.…
Okay, so we'll copy those and we'll paste them in here below the x definition.…Okay. So this is a while loop.…And the contents of the while loop, and again you can see that it's indented.…So that indicates that these lines of code belong to the while loop and not up here…in the main part of the function. So a while loop executes while the…condition contained inside these parenthesis is true.…
So while x is less than 5, we're going to print the value of X, and then we're going…to increment X by 1. Now some languages like C, provide a whole…
- Installing Python
- Choosing an editor/IDE
- Working with variables and expressions
- Writing loops
- Using the date, time, and datetime classes
- Reading and writing files
- Fetching Internet data
- Parsing and processing HTML
Skill Level Beginner
1. Preparing the Development Environment
2. Python Basics
3. Working with Dates and Times
4. Working with Files
5. Working with Web Data
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.