Ending a loop with break
You've used break since your first loops: it ends the loop at once, and the program goes on with the first line after the loop. Now that a loop can have a condition, many loops can be written either way. These two programs both count the guests typed in, until the user types done:
guests = 0
while True:
name = input("Guest: ")
if name == "done":
break
guests += 1
print(f"{guests} guests")
Ada
Linus
doneGuest: Ada
Guest: Linus
Guest: done
2 guestsguests = 0
name = ""
while name != "done":
name = input("Guest: ")
if name != "done":
guests += 1
print(f"{guests} guests")
With the same input, they print the same. But the second one needs a start value for name that's there only to get the loop going, and it checks for done twice: once in the condition and once more in the body, so that the word done isn't counted as a guest. With break, the check is in one place, right after the input. That's why a loop that reads input until some stop word is usually written with while True and break.
A condition and a break together
A loop can have both: a condition for the usual way out, and a break for an early one. This bake sale goes on until 50 cookies are sold, unless the seller types 0 to close early:
sold = 0
while sold < 50:
cookies = int(input("Cookies sold (0 to close): "))
if cookies == 0:
break
sold += cookies
print(f"{sold} cookies sold")
12
20
0Cookies sold (0 to close): 12
Cookies sold (0 to close): 20
Cookies sold (0 to close): 0
32 cookies soldHere the seller closed early. With the input 30 and 25, the loop would end by its condition instead: after the second round sold is 55, 55 < 50 is false, and the program prints 55 cookies sold without asking again.
Either way, the program goes on after the loop. If it needs to know which way the loop ended, it can check afterwards, for example with if sold >= 50:.