Latest web development tutorials

Python loop

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:

loop_architecture

Python provides for loop and while loop (no do..while 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

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.