How to use the python Loop Control statement break/continue
This article will explain in detail how to use the python loop control statement break/continue. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
Two keywords are provided in Python to control loop statements, namely break and continue
When the condition is established, break will not execute the subsequent code in the loop and will stop the entire loop
When the condition is established, continue will not execute the subsequent code in the loop and will stop the loop
Next, we use two cases to distinguish between the two control statements.
First, use the while loop statement to print a number between 1 and 5. When we loop to 3, we use the continue keyword to jump out of this loop. It should be noted that when the condition is established, continue will not execute the subsequent code. If the condition of the loop is not changed before the continue keyword, then the condition of the loop will not change, resulting in an endless loop.
I = print 1 to 5while I in a loop