代码如下(for):
for ch in 'python':
if ch == 't':
break
print ('current letter:',ch)
运行结果:
=================== RESTART: C:/Users/公有制/Desktop/four.py ===================
current letter: p
current letter: y
这是python3的写法,这种写法和c语言有点相似。
代码如下(while):
n = 10
while n > 1:
print('n = ',n)
if n < 5:
break
n = n - 1
运行结果:
=================== RESTART: C:/Users/公有制/Desktop/four.py ===================
n = 10
n = 9
n = 8
n = 7
n = 6
n = 5
n = 4