Oct-20-2019, 03:22 AM
Check out this very basic while loop in Python:
My million dollar question for all of you: For the purpose of while loops in general, is it safe to say that the
I realize that lines 5 and 6 really aren't necessary because even without them the loop would continue to perform as I described above. I added the
In case I need to refer back to the source or origin of this question, I got this idea from Andrei Neagoie's Udemy course content for "Complete Python Developer in 2019" (Section 4: Lecture 71: "While Loops 2").
while True:
response = input("Say something: ")
if response == 'bye':
break
if response != 'bye':
continue This script prompts the user for input. If the user would like to say hello (or really just about anything), the loop will continually prompt the user for a new response until the user finally enters: "bye". If the answer is "bye", the loop breaks. My million dollar question for all of you: For the purpose of while loops in general, is it safe to say that the
break operator turns a while condition from True to False, therefore exiting the loop?I realize that lines 5 and 6 really aren't necessary because even without them the loop would continue to perform as I described above. I added the
continue operator to demonstrate the distinction between break (turning the while condition to False) and 'continue' (allowing the while condition to remain True).In case I need to refer back to the source or origin of this question, I got this idea from Andrei Neagoie's Udemy course content for "Complete Python Developer in 2019" (Section 4: Lecture 71: "While Loops 2").
