sum = 0.0
while True:
= input('Enter a number: ')
data if data == '':
break
sum += float(data)
print('The sum is', sum)
Break and continue
- A
break
statement in a loop causes an immediate exit of the loop.
- What does this code do?
= 0
i while i < 5:
+= 1
i 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!