Repetition Structures - GramercyDatadata items. Statement(s) execute once for each item in the...
39
Repetition Structures cause statement(s) to execute repeatedly.
Transcript of Repetition Structures - GramercyDatadata items. Statement(s) execute once for each item in the...
Agenda1. The while loop - a condition-controlled loop2. The for loop - a count-controlled loop
3. Infinite loops
4. The range() function is often used with for loops.
5. The Augmented Assignment Operators: += -= *= /= %=
The while loop exampleThis condition is tested.
If the condition is true, these statements are executed, and then the loop starts over.
The for loopThe for statement is designed to work with a sequence of data items. Statement(s) execute once for each item in the sequence.
The range() function is often used with for loops.
Writing an Input Validation Loop
Retail price = wholesale cost * 2.5
Wholesale cost cannot be negative.