在Python中继续执行语句
Python继续声明
像其他编程语言一样,在python中,在python中,continue语句用于通过跳过循环中continue语句之后编写的其余语句来继续执行循环。
Continue语句不会终止循环执行,它会跳过循环的当前迭代并继续执行循环。
continue语句的语法:
continue
继续语句的Python示例
示例1:在这里,我们打印从1到10的严重数字,并且如果counter的值等于7,则继续循环(不打印)。
#继续语句的python示例
counter = 1
#循环1到10
#如果counter==7终止
while counter<=10:
if counter == 7:
counter += 1 #增加柜台
continue
print(counter)
counter += 1
print("outside of the loop")输出结果
1 2 3 4 5 6 8 9 10 outside of the loop
示例2:在这里,我们正在打印字符串的字符,如果字符不是字母,则继续循环打印字符。
#继续语句的python示例
string = "NHOOO.Com"
#如果终止循环
#任何字符都不是字母
for ch in string:
if not((ch>='A' and ch<='Z') or (ch>='a' and ch<='z')):
continue
print(ch)
print("outside of the loop")输出结果
I n c l u d e H e l p C o m outside of the loop