4.3_控制流3break_continue__pass.docx
4.3_控制流3break_continue__pass.docx
1. break
Python break语句,就像在C语言中,打破了最小封闭for或while循环。
break语句用来终止循环语句,即循环条件没有False条件或者序列还没被完全递归完,也会停止执行循环语句。
如果您使用嵌套循环,break语句将停止执行最深层的循环,并开始执行下一行代码。
当期字母: P 当期字母: y 当期字母: t 当期变量值:10当期变量值: 9当期变量值: 8当期变量值: 7当期变量值: 6Good bye!
2. continue
Python continue 语句跳出本次循环,而break跳出整个循环。
continue 语句用来告诉Python跳过当前循环的剩余语句,然后继续进行下一轮循环。
当前字母: P 当前字母: y 当前字母: t 当前字母: o 当前字母: n 当前变量值:9当前变量值: 8当前变量值: 7当前变量值: 6当前变量值: 4当前变量值: 3当前变量值: 2当前变量值: 1当前变量值: 0Good bye!
3. pass
Python pass是空语句,是为了保持程序结构的完整性。
当前字母: P 当前字母: y 当前字母: t 这是pass块当前字母: h 当前字母: o 当前字母: n Good bye!
guess = int(input('Enter an integer : '))
print('No, the number is higher than that, keep guessing')
# You can do whatever you want in a block ...
print('No, the number is a lower than that, keep guessing')
# you must have guessed > number to reach here
print('Bingo! you guessed it right.')
print('(but you do not win any prizes!)')
