week 6 nested loops Flashcards
while
executes code as long as statement is true, you want it to be the condition you don’t want so it runs until it meets you goal
while loop syntax
while (condition):
# code
sentinel while loop
has expected value, loops run while you don’t have the expected value
counting while loop
loop runs a set number of times and the iteration value is increased inside the while loop
for loops
initializes increment value and step size within first line
for i in range(1, 4, 1):
what is the significance of each number?
1 is the initial value (inclusive)
4 is end value (exclusive)
1 is step size
range(5)
0 1 2 3 4
for each
for loops iterates over container and accesses each element of the container
for each syntax
for ch in text:
# code
loop
program construct that repeatedly execute statements based on set conditions
iterations
each time through the loop’s statements are executed
loop body
code inside the loop
sentinel value
expected value you want to reach after the loop is executed
infinite loop
loop will always execute because expression is always true
how do you exit an infinite loop?
ctrl-c