CSC 161 Lecture Notes - Lecture 7: Infinite Loop, Empty String, Boolean Expression

21 views4 pages

Document Summary

The while loop requires us to manage the loop variable i by initializing it to 0 before the loop and incrementing it at the bottom of the body in the for loop this is handled automatically. The while statement is simple, but yet powerful and dangerous they are a common source of program errors. When python gets to this loop, i is equal to 0, which is less than 10, so the body of the loop is executed, printing 0. Now control returns to the condition, and since i is still 0, the loop repeats, etc: this is an example of an infinite loop. What should you do if you"re caught in an infinite loop: first, try pressing control-c if that doesn"t work, try control-alt-delete* At each iteration of the loop, ask the user if there is more data to process. We need to preset it to yes to go through the loop the first time.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents