sum = 0.0
while True:
data = input('Enter a number: ')
if data == '':
break
sum += float(data)
print('The sum is', sum)Break and continue
- A
breakstatement in a loop causes an immediate exit of the loop.
- What does this code do?
i = 0
while i < 5:
i += 1
if i==2:
continue
print(i)1
3
4
5
What does this code do?
Breaks and continues can sometimes simplify a loop’s structure and improve readability!