ECS 32A Lecture 11: While Loops
ECS 32A verified notes
11/30View all
Document Summary
Indents are typically 4 spaces or press the tab key. Each line of code should not be more than 80 characters long. My_string = ( this is a very long string . For list and dictionaries, indent after each item. Loops consist of two components: condition and body. Each time the loop body is called is called an iteration. If loops conditions is never satisfied, this would be an infinite loop. The most common case where we have while loops is when we wait for inputs. When you want to collect a quantity or values in a while loop, create the variable before you enter the loop. We can break infinite loops with a break statement. Skips the rest of the loop iteration, goes right back up top and checks the condition. While true: #infinite loop declaration deci = int(intput( enter a number: ))