1.遍历循环
for i in range(5) for i in range (M,N,K) for c in s: for c in 'python' print(c,end="") for i in fi : #系统打开文件
2.无线循环
while c>0: 语句块
3.break与continue
break:结束当前循环结构,进入循环体后面的语句(单层) continue:结束当次循环体后面的内容,继续重新进入循环体
s='python' while s != "": for c in s: print (c,end="") s = s[:-1] #从前面第一关取到最后,但不包括最后一位 #输出结果为:pythonpythopythpytpyp s='python' while s != "": for c in s: if c == "T": break print (c,end="") s = s[:-1] #输出结果为:pypypypypyp
4.高级循环 循环与else
else:正常退出循环的“”奖励”,即没有执行break
for(while) : <语句> else: #语句中若无break,else部分一定会执行 for c in 'pyYhon': if c == 't': break print(c,end = '') else: print(' 字符串里面没有t')