Difference between break and continue with examples

Break is used to stop and come out of a loop.
example:
i=1
while i<9:
print(i, end=" ")
if i==4:
break
i+=1
it will return 1 2 3 4

Continue used to skip specific value and continue iteration .
Example: for i in range (1,9):
if i==3:
continue
print(i,end=" ")
it returns 1 2 4 5 6 7 8

2 Likes

Correct :100:. Very good…keep practicing​:+1:

break and continue both are loop control statement
break :- program to show the use of the break statement inside the loop
ex. val in “string”
if val==“i”
break
print(val)
print(“the end”)

output;- s t r

continue:- continue use to skip specific value and gives continue iteration
ex:- val in “string”
if val==“i”
continue
print(val)
print(“the end”)

output:- s t r n g

1 Like

@dhanashrip930

Correct, keep it up.
Keep Practicing.