CMPT 120 Chapter Notes - Chapter 3: Infinite Loop
meghan78 and 39786 others unlocked
29
CMPT 120 Full Course Notes
Verified Note
29 documents
Document Summary
When the while loop runs, these steps are repeated: check the value of the loop condition. If it"s false, the loop exits, and the program moves on to the following code: run the loop body. Basically, the while loop uses its condition to ask should i keep going? if so, it runs the loop once more and asks again. When you use an indefinite loop, you have to make sure that the loop condition eventually becomes false. If not, your program will just sit there looping forever. Before you can choose a control structure, you need to have a pretty good idea what you want the computer to do: you need to have an algorithm in mind. Once you do, you can then think about how to get a program to do what you want. Most statements in python (and most other programming languages) are executed in the order that they appear.