循环语句有以下几种语句:
while语句
在给定的判断条件为 true 时执行循环体,否则退出循环体。
for语句
重复执行语句
嵌套循环
你可以在while循环体中嵌套for循环
循环控制语句
循环控制语句可以更改语句执行的顺序。Python支持以下循环控制语句:
break 语句
在语句块执行过程中终止循环,并且跳出整个循环
continue 语句
在语句块执行过程中终止当前循环,跳出该次循环,执行下一次循环。
pass 语句
pass是空语句,是为了保持程序结构的完整性。
while循环:
while循环的几种用法:
1,普通用法
# -*- coding: UTF-8 -*-
count = 0
while (count < 9):
print ('The count is:', count)
count = count + 1
print ("Good bye!")
while 语句时还有另外两个重要的命令 continue,break 来跳过循环,continue 用于跳过该次循环,break 则是用于退出循环,此外"判断条件"还可以是个常值,表示循环必定成立,
2, whlie…else
在 python 中,while … else 在循环条件为 false 时执行 else 语句块:
# -*- coding: UTF-8 -*-
count =