Gavin Restifo March 1, 2019 Today: Repetition Part 2 - For Loops CS 1110 Gavin Restifo March 1, 2019 Today: Repetition Part 2 - For Loops
Last time While loops Strategies for repetitive code Needs 3 things Condition Something to be repeated Adjust the condition Strategies for repetitive code Top down Start with the loop Bottom up Start with everything else and repeat
Today: For loops Similar to while Does not require a condition Instead requires a collection Almost everything you can do with while you can do with for What might you not be able to do with for? Keywords: for in
Syntax for something in collection: # Repeat this code For Something Iterate through whatever you give it Something Assigned in the loop In Specifies the set of iteration Collection Whatever we want to loop through
Collections (so far) Strings Ranges Lists Tuples*