Python loop statement
This chapter will introduce you to Python’s loop statements. Under normal circumstances, programs are executed in sequence.
Programming languages provide various control structures that allow more complex execution paths.
Loop statements allow us to execute a statement or group of statements multiple times. The following is the general form of loop statements in most programming languages:
Python provides for loops and while Loop (no do..while loop in Python):
Loop type | Description |
---|---|
while Loop | Execute the loop body when the given judgment condition is true, otherwise exit the loop body. |
for loop | Repeated execution statement |
Nested loop | You can use the while loop body Nested for loop |
Loop control statement
Loop control statement can change the order of statement execution. Python supports the following loop control statements:
Control statement | Description |
---|---|
break statement | Terminate the loop during the execution of the statement block, and jump out of the entire loop |
continue statement | Terminate the current loop during the execution of the statement block, jump out of the loop, and execute Next cycle. |
pass statement | pass is an empty statement to maintain the integrity of the program structure. |