Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the python Loop Control statement break/continue

Shulou Source: shulou.com Published: 2022-06-03 20:11:16 09月19日 Update

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

Tags: Loop keyword condition statement control two code number time article next more result good practical in between content article case Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Microsoft vpn Xiaomi macOS