Python跳出循环语句break与continue的区别

在Python中,break与continue都是常用的跳出for循环语句的指令,两者的区别用下面的简单代码示例即可以分辨清楚

continue:在循环体中,跳过i==5的循环,但继续执行之后的所有循环

for i in range(0, 10):
    if i == 5:        
        continue      
    print i           

continue输出:

C:\Python27\ArcGIS10.2\python.exe "H:/04.JING Chenlin/codes/222.py"
0
1
2
3
4
6
7
8
9

Process finished with exit code 0

break:直接跳出循环

for i in range(0, 10):    
    if i == 5:            
        break             
    print i               

break输出:

C:\Python27\ArcGIS10.2\python.exe "H:/04.JING Chenlin/codes/222.py"
0
1
2
3
4

Process finished with exit code 0

你可能感兴趣的:(遥感,Python,循环语句)