CSE 1010 Lecture 7: CSE1010 Lecture 7 - While Loops

20 views2 pages
Verified Note

Document Summary

While loop: while loops are a way to repeat statements as long as a condition is true. While loop format: while condition: statements increment variable. It is very important to increment the variable that you are using. If the increment is missing, the loop will continue forever. If the condition is true, run the statement. The statement will continue to run as long as the condition is true. If the condition is false, exit the loop. While n<=5 print(n) n = n+1 #this statement increments n by 1. Note that you exit the loop when n = 5 and n remains being 5, not 6. Break statement: with the break statement the loop can be stopped even when the condition is true. Example: n = 1 while n<8 print(n) if n==3 break #exit the loop when n=3 n = n+1. Continue statement: with the continue statement the current iteration can be stopped, and continue with the next.

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

Related Questions