The best Python loop Tutorial In 2024, In this tutorial you can learn Loop control statements,
This chapter will introduce Python's loop, the program is generally executed sequentially.
Programming languages provide various control structures, allows more complex execution paths.
Loop allows us to perform a statement or group of statements repeatedly, the following is the general form in most programming languages of the loop:
Python provides for loop and while loop (no do/enwhile loop in Python):
Type of cycle | description |
---|---|
while loop | Loop body is executed at the time of the judgment given condition is true, otherwise exit the loop. |
for loop | Repeat statement |
Nested loop | You can be nested for loop in while loop body |
Loop control statements can change the order of statement execution. Python loop control supports the following statements:
Control statements | description |
---|---|
break statement | It terminates the loop during the execution of the statement block and out of the entire cycle |
continue Statement | Termination statement block in the implementation process of the current cycle, jump out of the cycle, the next time through the loop. |
pass sentence | pass is an empty statement, in order to maintain the integrity of the program structure. |