In addition to the while condition, there are two methods to terminate the loop: Break and continue. The only difference between them is that break jumps out of the entire loop and executes the following code directly. Continue terminates the current loop and directly enters the next loop without executing the following code, the difference between continue and pass is that although pass does not do anything, it continues to execute the following code. The following code illustrates the difference between break and continue.
Break:
Count =0WhileCount <= 100:Print('Loop', Count)IfCount = 5:BreakCount+ = 1Print("Out of loop ----")"""Loop 0 loop 1 loop 2 loop 3 Loop 4 loop 5out of Loop"""
After the break statement is executed, the loop is terminated directly.
Continue:
Count =0WhileCount <= 100:Print('Loop', Count)IfCount = 5:ContinueCount+ = 1Print("Out of loop ----")#Infinite Loop 5
When Count = 5, the program starts to continue. Instead, the program enters the next loop. Because count does not add 1, so in the next loop, count is equal to 5, and so is next time. Next time ......
Difference between continue and break in a while loop