Lesson 9 Flashcards
For loops
allow us to repeat code multiple times. It makes programs easier and simpler to read. You must have 4 spaces in front of the code that is part of the loop so that python recognizes that they are the same code
i
The traditional name for a counter variable. It will represent the current value of the loop.
in is a keyword
It shows that you are about to specify how many times the loop should repeat.
range()function
tells the loop to stop before the number listed in the range function. range(3) it goes from 0-2. It counts where a counter variable starts, ends, and the increment it goes up by. (4,13,4) It will count from 4 to 13 by increments of 4.
for i in range(3):
an example of a for loop.
Indented code
indicates the code is part of a loop listed before. Don’t indent if you want to start code outside of the loop
While loops
repeats as long as the conditional statement is true. l It replaces the counting portion with a conditional statement. Keyword is “while.”
Nested loop
a loop in another loop.
While loop formula
while Booleanexpression :