CSE 1010 Lecture 7: CSE 1010 - Lecture 7 - For Loops

64 views2 pages
Verified Note

Document Summary

Cse 1010 - introduction to computing for engineers. If guess < num: print(cid:383)(cid:361)too low(cid:362)(cid:384) elif guess > num: print(cid:383)(cid:361)too high(cid:362)(cid:384) print(cid:383)(cid:361)correct! (cid:362)(cid:384) #this will only print when the while loop is terminated/when the while loop is finalized as true. This is from section 4. 2 from the python tutorial. The condition can be any expression that evaluates to true or false. Iterates over a list or range while a condition is true. Useful when you don"t know how many times you must iterate. As well as when you do know how many times you must iterate. Example: nums = [10, 20, 30, 40] for n in nums: print(n) In the example above, the for loop takes each number out of the nums variable and puts it into n . For each value that is taken from the list, it executes the body of the loop one time each. There are no incrementors in for loops!

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