Both of the Python loop statements provide additional controls for short circuits, breaking out of the loop, and for processing a successful exit.
- [Instructor] Both the while and for loops…have some additional controls that are worth understanding.…Three additional controls are available…continue, break, and else.…The continue clause is used to shortcut a loop…and start it again as if it had…reached the end of its body of code.…The break clause is used to break out of a loop prematurely,…execution will continue after the entire loop structure…and the else control is not common in other languages…so you may not have seen this before.…
The else block executes only if the loop ends normally.…It will not execute if a break is used to end the loop.…These same controls are available for both…while and for loops.…For example, here in Komodo I have opened…a working copy of while.py…from chapter six of the exercise files…and I'm just going to add a couple of variables here.…We'll have an auth equals false…and that'll be true if the user is authorized.…
We'll have a count to count the number of attempts…and a max attempt…with a maximum number of attempts it will allow.…
- Python anatomy
- Types and values
- Conditionals and operators
- Building loops
- Defining functions
- Python data structures: lists, tuples, sets, and more
- Creating classes
- Handling exceptions
- Working with strings
- File input/output (I/O)
- Creating modules
- Integrating a database with Python db-api
Skill Level Intermediate
Python: Programming Efficientlywith Michele Vallisneri2h 15m Intermediate
2. Language Overview
3. Types and Values
8. Structured Data
11. String Objects
12. File I/O
13. Built-in Functions
- 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.