break

终止整个循环:当循环或判断执行到break语句时,即使判断条件为True或者序列尚未完全被历遍,都会跳出循环或判断

for i in xrange(10):
print(i)
if i == 8:
break
print('end') 执行:
C:\Python27\python.exe D:/Python/type-of-data.py
0
1
2
3
4
5
6
7
8
end Process finished with exit code 0

continue

跳出当次循环

当循环或判断执行到continue语句时,continue后的语句将不再执行,会跳出当次循环,继续执行循环中的下一次循环

for i in xrange(10):
if i ==3:
print('lalalalalalala')
continue
print(i) print('end') 执行:
C:\Python27\python.exe D:/Python/type-of-data.py
0
1
2
lalalalalalala
4
5
6
7
8
9
end Process finished with exit code 0

总结:

continue 语句跳出本次循环,只跳过本次循环continue后的语句

break 语句跳出整个循环体,循环体中未执行的循环将不会执行

for i in xrange(10):
if i ==3:
print('lalalalalalala')
continue
print(i)
if i == 8:
break
print('end') 执行:
C:\Python27\python.exe D:/Python/type-of-data.py
0
1
2
lalalalalalala
4
5
6
7
8
end Process finished with exit code 0

python - break和continue的更多相关文章

  1. Python - break、continue 的使用

    前置知识 break.continue 会结合循环使用的,所以要先学会循环哦 python 提供了两种循环语句 for 循环:https://www.cnblogs.com/poloyy/p/1508 ...

  2. 记录今天学习python中for与while循环针对break和continue的用法

    python中有两个主要的循环for与while,其中针对这两个循环有两种不同的中断用法break与continue. 首先先看下面的循环代码: 1: for i in range(10):#变量i带 ...

  3. python 语句:条件、循环、break、continue...

    1. 条件语句 执行条件:判断条件"成立时(非零),则执行后面的语句,而执行内容可以多行,以缩进来区分表示同一范围. [Python程序语言指定任何非0和非空(null)值为true,0 或 ...

  4. Python循环语句之break与continue的用法

    摘自原文章: http://www.jb51.net/article/73383.htm Python break 语句Python break语句,就像在C语言中,打破了最小封闭for或while循 ...

  5. Python基础(3)if_else、for、while、break与continue

    1.if ... else a=6 if a>=5: print("The a is bigger than 5") else: print("The a is s ...

  6. Python3基础(1)Python介绍、Python2 与Python3、变量、用户输入、if...else和for循环、while循环、break与continue

    ---------------个人学习笔记--------------- ----------------本文作者吴疆-------------- ------点击此处链接至博客园原文------ P ...

  7. python(3)-- 语句:条件、循环、break、continue...

    1. 条件语句 执行条件:判断条件"成立时(非零),则执行后面的语句,而执行内容可以多行,以缩进来区分表示同一范围. [Python程序语言指定任何非0和非空(null)值为true,0 或 ...

  8. python中break、continue 、exit() 、pass终止循环的区别

    python中break.continue .exit() .pass区分 1.break:跳出循环,不再执行 Python break语句,就像在C语言中,打破了最小封闭for或while循环. b ...

  9. Python 循环语句(break和continue)

    Python 循环语句(break和continue) while 语句时还有另外两个重要的命令 continue,break 来跳过循环,continue 用于跳过该次循环,break 则是用于退出 ...

随机推荐

  1. WebUploader压缩图片上传

    WebUploader,由Baidu FEX 团队开发,以H5为主,FLASH为辅,兼容 IE6+,iOS 6+, android 4+,采用大文件分片并发上传,极大的提高了文件上传效率,看了官方文档 ...

  2. 20190103(GIL,池,阻塞,同步异步)

    GIL锁 什么是GIL GIL全局解释器锁,是防止多个线程在同一时间同时执行的.CPython解释器特有的一种互斥锁. 每一个py文件都会有自己的解释器,也就是说不同py文件的GIL都是独立的, ps ...

  3. 2017 ACM-ICPC网络赛 H.Skiing 有向图最长路

    H.Skiing In this winter holiday, Bob has a plan for skiing at the mountain resort. This ski resort h ...

  4. 线程、进程、队列、IO多路模型

    操作系统工作原理介绍.线程.进程演化史.特点.区别.互斥锁.信号.事件.join.GIL.进程间通信.管道.队列.生产者消息者模型.异步模型.IO多路复用模型.select\poll\epoll 高性 ...

  5. AD管理中心

    (一).安装 Active Directory 管理中心 引用位置: http://technet.microsoft.com/zh-cn/library/dd560652(WS.10).aspx ( ...

  6. Android事件分发机制浅析(3)

    本文来自网易云社区 作者:孙有军 我们只看最重要的部分 1: 事件为ACTION_DOWN时,执行了cancelAndClearTouchTargets函数,该函数主要清除上一次点击传递的路径,之后执 ...

  7. 【 Sqrt(x) 】cpp

    题目: Implement int sqrt(int x). Compute and return the square root of x. 代码: class Solution { public: ...

  8. php代码审计 strcmp和MD5函数漏洞

    通过get得到三个值,v1,v2,v3. if第一层判断,v1和v2得到的值不一样,但是对它们进行md5加密后的值得相等. if第二层判断,v3得到的值得和$flag的值相等,满足这两个条件输出fla ...

  9. mysql数据库增、删、改、查等基本命令

    测试环境:windows7 64位 mysql.exe.Navicat Lite for MySQL.mysql 5.0.18 mysql数据库的基本结构: 数据库(database)包含多个表(ta ...

  10. Halcon18 Mac os 下载

    Halcon18 Mac os 下载地址:http://www.211xun.com/download_page_15.html HALCON 18 是一套机器视觉图像处理库,由一千多个算子以及底层的 ...