Python Language / Break and Continue Statements

Continue Statement
It is used to stop the current iteration, and continue with the next.

Program to find sum of first 5 numbers Output

sum = 0
i = 1
while i <= 5:
sum = sum + i
i = i+1
if i == 3:
break
print("The sum is", sum)

The sum is 3>


Break Statement
Example Output

sum = 0
i = 1
while i <= 5:
sum = sum + i
i = i+1
if i == 3:
continue
print("The sum is", sum)

The sum is 15


Home     Back