Title: While Statement
Course: CPS 120: Introduction to Computer Science ~ Master (Aug/2015) OLD > Section: Learning Units

Python While statement:

- Is a statement with a condition and one or two blocks of code.
- The condition is tested:
✓ If the condition is True, then the first block of code executes, and the condition is tested again.
✓ If the condition is False and the second block of code exists, then that block executes.
- Is a form of indefinite iteration – we don’t know exactly how many times the first block will execute.
- The first block may run 0 or more times.
- Every loop must have three parts:
✓ An initialization
✓ A condition
✓ An update
- If any part is missing, the loop will fail.

<block>
is the same as
statement-1;
statement-2;
…
statement-n;

There are two layouts which you will explore on the next pages.