Python basic in...login
Python basic introductory tutorial
author:php.cn  update time:2022-04-18 16:14:50

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:

loop_architecture.jpg

Python provides for loops and while Loop (no do..while loop in Python):

Loop typeDescription
while LoopExecute the loop body when the given judgment condition is true, otherwise exit the loop body.
for loopRepeated execution statement
Nested loopYou 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 statementDescription
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.

php.cn