INFO1110 Lecture Notes - Lecture 4: Negative Number, Order Of Merit
Document Summary
When writing while loops for counting, keep 3 things in mind: initialise a counter variable, update the counter variable, ensure there is a stopping condition i = 0 while i < 5: print(i) i = i + 1. You can force exit a loop by using break you can force a reiteration (go back to start) with continue. How to end a loop: ask before iterating: ask the user if it is time to end the loop. A user can end a loop by entering a sentinel value. For example, enter all test scores followed by negative number: using break and continue keywords. Using break and continue can add complexity and should be avoided, if possible. A owchart can be used to easily convey the control ow and execution paths of a program: boxes represent code statements, diamonds represent conditions, i. e. decision points. If a diamond does not have an arrow going back to it, it"s an if statement.