Loop Concept
Driving around the block until your baby falls asleep.
Loop
A loop is just like a branch but the loop jumps back to the top and will continue to iterate while the loop’s expression is true.
While Loop
This kind of loop is used when you don’t know how many iterations you need to do. The loop will continue to run as long as the conditions are true.
For Loop
Use these when you know how many iterations you need the loop to make.
Counting with a While Loop
You can update each iteration of your loop until the loop condition is false. (+=, *=, or /=)
For Loop
reversed()
This function makes the for loop iterate BACKWARDS starting with the last element and ending with the first.
for Loop
range()
This function allow for counting in for loops as well.
Nested Loops
Is a loop that appear as part of the body of another loop. You can call then outer loops and inner loops
Incremental Programming
Is a way to minimize debugging. Start with a simple version of your program and grow it little by little into the complete version.
Break statements
A break statement in a loop causes the loop to exit immediately. Used to make a loop easier to understand.
Continue Statements
A continue statement in a loop causes an immediate jump the while OR for loop header statement. Used to improve readability.
Loop Else
A loop can include an else clause that executes ONLY if the loop terminates normally and doesn’t use a break statement.
enumerate()
This function retrieves BOTH the index and its corresponding element value at the same time. Used to make things clean and readable.