Summary

Control flow allows programs to execute nonsequentially using the if, while, and for compound statements. if conditionally executes a statement, while executes a statement while a condition is true, and for iterates through a sequence. All three can contain else clauses that execute when the if condition is false, when it becomes false, or when the items in a list are or become empty, respectively.

As compound statements, if, while, and for contain clauses. Clauses contain suites and control their execution. if contains if, elif, and else clauses; while contains while and else clauses; and for contains for and else clauses. Within the while and for statements, break and continue, as their names imply, break out of a loop and continue ...

Get Python Programming with the Java™ Class Libraries: A Tutorial for Building Web and Enterprise Applications with Jython now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.