While Loop is a type of loop that is used when you don’t know exactly how many times the code will repeat. The main characteristic of a while loop is that it will repeat a set of instructions based on a condition.
i = 1 while i < 6: print(i) i += 1
The break statement in programming has the following two usages –
- When a break statement is encountered inside a loop, the loop is immediately terminated and the program control resumes at the next statement following the loop.
- It can be used to terminate a case in the switch statement
i = 1 while i < 6: print(i) if i == 3: break i += 1
It forces the next iteration of the loop to take place, skipping any code in between
i = 0 while i < 6: i += 1 if i == 3: continue print(i)