December 2000
Intermediate to advanced
816 pages
16h 57m
English
In C (as well as in most other languages), you will not find an else statement outside the realm of conditional statements, yet Python bucks the trend again by offering these in while or for loops. How do they work? When used with loops, an else clause will be executed only if a loop finishes to completion, meaning they were not abandoned by break.
One popular example of else usage in a while statement is in finding the largest factor of a number. We have implemented a function which performs this task, using the else statement with our while loop. The showMaxFactor() function in Example 8.1 (maxFact.py) utilizes the else statement as part of a while loop.
|
This program ... |
Read now
Unlock full access