一、continue的使用方法(结束当前的循序,进行下一个数的循环)

# *****************************************************************************
# This is a program to illustrate the useage of continue in Python.
# If you want to stop executing the current iteration of the loop and skip ahead to the next
# continue statement is what you need.
# ****************************************************************************
for i in range (1,6):
print
print 'i=',i,
print 'Hello,how',
if i==3:
continue
print 'are you today?'

执行结果例如以下:

>>> ================================ RESTART ======================

>>>



i= 1 Hello,how are you today?



i= 2 Hello,how are you today?



i= 3 Hello,how

i= 4 Hello,how are you today?

i= 5 Hello,how are you today?

>>>

二、break的使用方法(结束总的循环)

# *****************************************************************************
# This is a program to illustrate the useage of break in Python.
# What if we want to jump out of the loop completely—never finish counting, or give up
# waiting for the end condition? break statement does that.
# ****************************************************************************
for i in range (1,6):
print
print 'i=',i,
print 'Hello,what is ',
if i==3:
break
print 'the weather today?'

执行结果例如以下:

>>> ================================ RESTART ========================

>>>



i= 1 Hello,what is  the weather today?



i= 2 Hello,what is  the weather today?



i= 3 Hello,what is

>>>

Python中的break和continue的使用方法的更多相关文章

  1. 简述Python中的break和continue的区别

    众所周知在Python中,break是结束整个循环体,而continue则是结束本次循环再继续循环. 但是作为一个新手的你,还是不明白它们的区别,这里用一个生动的例子说明它们的区别,如下: 1.con ...

  2. python中的break 和continue的区别

    break语句可以在循环过程中直接退出循环,而continue语句可以提前结束本轮循环 break的例子如图,当遇到的n为偶数时,直接退出循环,所以打印的结果只有1. continue例子如下图,当遇 ...

  3. JAVA中的break[标签]continue[标签]用法

    原文:JAVA中的break[标签]continue[标签]用法 注意:JAVA中的标签必须放在循环之前,且中间不能有其他语句.例如:tag:for或while或do--while; 1.使用brea ...

  4. Java中的break和continue以及标签

    一.Java中的break,continue,goto 首先break,continue是Java中的关键字,而goto是保留字. 基于goto在c和c++中的鬼畜表现,我觉得goto可能还会长期在J ...

  5. Java中的break和continue关键字使用总结

    java中的break和continue关键字使用总结   一.作用和区别   break的作用是跳出当前循环块(for.while.do while)或程序块(switch).在循环块中的作用是跳出 ...

  6. JavaScript学习系列博客_12_JavaScript中的break、continue关键字

    break关键字 -break关键字可以用来退出switch或循环语句 -不能在if语句中使用break和continue,但不是说if语句里面不能写break关键字,break关键字一定要包含在sw ...

  7. Python中执行系统命令常见的几种方法--转载

    Python中执行系统命令常见的几种方法 Python中执行系统命令常见的几种方法有: (1)os.system # 仅仅在一个子终端运行系统命令,而不能获取命令执行后的返回信息 # 如果再命令行下执 ...

  8. Python中日期和时间格式化输出的方法

    本文转自:https://www.jb51.net/article/62518.htm 本文实例总结了python中日期和时间格式化输出的方法.分享给大家供大家参考.具体分析如下: python格式化 ...

  9. python中readline判断文件读取结束的方法

    注:内容来自网络 本文实例讲述了python中readline判断文件读取结束的方法.分享给大家供大家参考.具体分析如下: 大家知道,python中按行读取文件可以使用readline函数,下面现介绍 ...

随机推荐

  1. Discuz常见小问题-如何修改UCenter创始人密码

    http://faq.comsenz.com/viewnews-925 参照上面这个帖子,把tools.php下载下来并放到uc_server目录下,打开文件,找到第10行设置一个初始工具箱密码 ht ...

  2. ZH奶酪:JavaScript清空数组的三种方法

    参考链接:http://snandy.iteye.com/blog/893955 方式1,length赋值为0 目前 Prototype中数组的 clear 方法和mootools库中数组的 empt ...

  3. AS3的反编译

    一个as3写的swf反编译,修改类库: http://www.swfwire.com/ http://www.swfwire.com/decompiler 基于此类库的swf反编译工具(air) ht ...

  4. ubuntu server vsftpd 匿名用户上传下载及目录设置

    ubuntu server vsftpd 匿名用户上传下载及目录设置 1:vsftpd服务器安装: sudo apt-get install vsftpd #安装 cd /srv/ #切换到默认匿名用 ...

  5. uva 701 - The Archeologists' Dilemma

    题目链接:uva 701 - The Archeologists' Dilemma 题目大意:给出x,求一个e,使得x * 10 ^ y ≤ 2 ^ e < (x + 1) * 10 ^ y. ...

  6. 文件的上传Commons FileUpload(web基础学习笔记十六)

    一.表单设置 <form action="<%=request.getContextPath()%>/jsp/admin/doAdd.jsp" enctype=& ...

  7. 深入理解Object提供的阻塞和唤醒API

    深入理解Object提供的阻塞和唤醒API 前提 前段时间花了大量时间去研读JUC中同步器AbstractQueuedSynchronizer的源码实现,再结合很久之前看过的一篇关于Object提供的 ...

  8. OA项目实战学习(7)——初始化数据&amp;权限配置显示

    详细有哪些功能: 初始化数据 权限数据. 超级管理员. Installer.java package cn.xbmu.oa.install; import javax.annotation.Resou ...

  9. 纯jascript解决手机端拍照、选图后图片被旋转问题

    需要的js1 需要的js2 这里主要用到Orientation属性. Orientation属性说明如下: 旋转角度 参数 0° 1 顺时针90° 6 逆时针90° 8 180° 3 <!DOC ...

  10. 〖Linux〗build ssh for Arm

    1. 交叉编译环境: export ARCH=arm export SUBARCH=arm export PATH=/opt/FriendlyARM/toolschain//bin:$PATH exp ...