TEST YOUR KNOWLEDGE: WHILE LOOPS
Fill in the blank: A while loop instructs your computer to continuously execute your code based on the value of a _____.
A while loop instructs your computer to continuously execute your code based on the value of a condition. The loop will keep iterating as long as the condition remains true.
A data professional wants to set up a while loop that will iterate as long as the variable x is less than 7. They assign the value 0 to the variable x. What code should they write next?
The code while x < 7: sets a condition for a while loop stating that the variable x must be less than 7. The code begins with the distinguishing keyword while. And, like functions and other expressions that start a distinct code block, it ends with a colon. The while loop will iterate until the condition is false.
In Python, the keyword break lets you escape a loop without triggering any else statement that follows it in the loop.
In Python, the keyword break lets you escape a loop without triggering any else statement that follows it in the loop.
Ready to test your recall?
Fill in the blank: A while loop instructs your computer to continuously execute your code based on the value of a _____.
How confident are you in this answer?