python | looping and control

Introduction: Programs are generally executed sequentially, but Python provides various control structures that allow changing the order in which statements are executed: for loops, while loops, as well as break, continue, and pass statements.

Author: Han Xinzi
@ ShowMeAI Tutorial address :
article address :
: All rights reserved, please contact the platform and Author and credit

1. Python loop statement
Programs are generally executed sequentially, and Python provides various control structures that allow for more complex execution paths.
A loop statement allows us to execute a statement or group of statements multiple times. The following is the general form of a loop statement in most programming languages:

Python provides two control loops, for loop and while loop, which you can also nest:

Loop typedescribe
while loop
Execute the loop body when the given condition is true, otherwise exit the loop body.
for loop
Repeat statement
nested loopYou can nest for loops within the body of the while loop
2. Loop Control Statement
Loop control statements can change the order in which statements are executed. Python supports the following loop control statements:

control statementdescribe
break statement
Terminates the loop during execution of the statement block and exits the entire loop
continue statement
Terminate the current loop during the execution of the statement block, jump out of this loop, and execute the next loop.
pass statement
pass is an empty statement to maintain the integrity of the program structure.

Copyright statement: The content of this article is contributed by Alibaba Cloud real-name registered users. The copyright belongs to the original author. The Alibaba Cloud developer community does not own the copyright and does not assume the corresponding legal responsibility. For specific rules, please refer to the " Alibaba Cloud Developer Community User Service Agreement " and " Alibaba Cloud Developer Community Intellectual Property Protection Guidelines ". If you find any content suspected of plagiarism in this community, fill out the infringement complaint form to report it. Once verified, this community will delete the allegedly infringing content immediately.

Related Articles

Explore More Special Offers

  1. Short Message Service(SMS) & Mail Service

    50,000 email package starts as low as USD 1.99, 120 short messages start at only USD 1.00

phone Contact Us