break and continue

2018-07-21  本文已影响8人  苗_a

for的循环

name = 'dongGe'
for x in name:
print('----')
print(x)

带有break的循环

name = 'dongGe'
for x in name:
print('----')
if x == 'g':
break
print(x)

while的循环

i = 0
while i<10:
i = i+1
print('----')
print(i)

带有break的循环

i = 0

while i<10:
i = i+1
print('----')
if i==5:
break
print(i)#

continue的循环

for的循环 name = 'dongGe'

for x in name:
print('----')
if x == 'g':
continue
print(x)
i = 0

while i<10:
i = i+1
print('----')
if i==5:
continue
print(i)

break和continue举列子

用break求素数

VirtualBox_Ubuntu_21_07_2018_15_41_19.png

用continue执行

Image.png
上一篇下一篇

猜你喜欢

热点阅读