📅  最后修改于: 2020-12-23 05:12:36             🧑  作者: Mango
通常,语句是按顺序执行的:函数的第一个语句首先执行,然后第二个执行,依此类推。在某些情况下,您需要多次执行一个代码块。
编程语言提供了各种控制结构,允许更复杂的执行路径。
循环语句使我们可以多次执行一个语句或一组语句。下图说明了循环语句-
Python编程语言提供了以下类型的循环来处理循环需求。
Sr.No. | Loop Type & Description |
---|---|
1 | while loop
Repeats a statement or group of statements while a given condition is TRUE. It tests the condition before executing the loop body. |
2 | for loop
Executes a sequence of statements multiple times and abbreviates the code that manages the loop variable. |
3 | nested loops
You can use one or more loop inside any another while, for or do..while loop. |
循环控制语句从其正常顺序更改执行。当执行离开作用域时,在该作用域中创建的所有自动对象都将被销毁。
Python支持以下控制语句。单击以下链接以查看其详细信息。
让我们简要介绍一下循环控制语句
Sr.No. | Control Statement & Description |
---|---|
1 | break statement
Terminates the loop statement and transfers execution to the statement immediately following the loop. |
2 | continue statement
Causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating. |
3 | pass statement
The pass statement in Python is used when a statement is required syntactically but you do not want any command or code to execute. |