Back Navigation Next Navigation Conceptual Review (page 42 of 55)

We can also use a while loop to loop while a condition (Boolean expression) is True. The structure of a while loop is while Boolean expression:

Similar to conditional statements, the Boolean expression is to the left of the ":" and the indentation after the ":" indicates the scope (i.e. which code to execute) of the loop. While loops are called indefinite loops because the loop continues until a logical condition becomes False.

Looping

With while loops, we must be careful to program our "exit" logic. Failing to do so will inevitably result in an infinite loop where the loop never exits.