Python中的break和continue的使用方法
一、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 '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 '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的使用方法的更多相关文章
- 简述Python中的break和continue的区别
众所周知在Python中,break是结束整个循环体,而continue则是结束本次循环再继续循环. 但是作为一个新手的你,还是不明白它们的区别,这里用一个生动的例子说明它们的区别,如下: 1.con ...
- python中的break 和continue的区别
break语句可以在循环过程中直接退出循环,而continue语句可以提前结束本轮循环 break的例子如图,当遇到的n为偶数时,直接退出循环,所以打印的结果只有1. continue例子如下图,当遇 ...
- JAVA中的break[标签]continue[标签]用法
原文:JAVA中的break[标签]continue[标签]用法 注意:JAVA中的标签必须放在循环之前,且中间不能有其他语句.例如:tag:for或while或do--while; 1.使用brea ...
- Java中的break和continue以及标签
一.Java中的break,continue,goto 首先break,continue是Java中的关键字,而goto是保留字. 基于goto在c和c++中的鬼畜表现,我觉得goto可能还会长期在J ...
- Java中的break和continue关键字使用总结
java中的break和continue关键字使用总结 一.作用和区别 break的作用是跳出当前循环块(for.while.do while)或程序块(switch).在循环块中的作用是跳出 ...
- JavaScript学习系列博客_12_JavaScript中的break、continue关键字
break关键字 -break关键字可以用来退出switch或循环语句 -不能在if语句中使用break和continue,但不是说if语句里面不能写break关键字,break关键字一定要包含在sw ...
- Python中执行系统命令常见的几种方法--转载
Python中执行系统命令常见的几种方法 Python中执行系统命令常见的几种方法有: (1)os.system # 仅仅在一个子终端运行系统命令,而不能获取命令执行后的返回信息 # 如果再命令行下执 ...
- Python中日期和时间格式化输出的方法
本文转自:https://www.jb51.net/article/62518.htm 本文实例总结了python中日期和时间格式化输出的方法.分享给大家供大家参考.具体分析如下: python格式化 ...
- python中readline判断文件读取结束的方法
注:内容来自网络 本文实例讲述了python中readline判断文件读取结束的方法.分享给大家供大家参考.具体分析如下: 大家知道,python中按行读取文件可以使用readline函数,下面现介绍 ...
随机推荐
- java编程思想---对象
一.对象 对于每种语言来说,都有自己操纵内存中元素的方法. 在java中,一切被视为对象.可是操纵对象的是一个"引用".举个样例,能够比作为遥控器对电视的操作,遥控器就是引用,而电 ...
- Session 共享(Custom模式)By Memcached(原创)
1.web.config配置: <machineKey decryptionKey="FD69B2EB9A11E3063518F1932E314E4AA1577BF0B824F369& ...
- HDU1698:Just a Hook(线段树区间更新)
Problem Description In the game of DotA, Pudge’s meat hook is actually the most horrible thing for m ...
- strcpy sprintf memcpy 它们之间的区别
strcpy,sprintf,memcpy的区别 strcpy 函数操作的对象是 字符串,完成 从 源字符串 到 目的字符串 的 拷贝 功能. snprintf 函数操作的对象 不限于字符串:虽然目 ...
- Linux虚拟机下使用USB转串口线——配置minicom、以及screen的使用
转自:http://bbs.ednchina.com/BLOG_ARTICLE_637212.HTM 环境:Windows XP + (VMware Workstation - Linux) 1.确保 ...
- CSDN开源夏令营 基于Compiz的switcher插件设计与实现之compiz特效插件介绍及特效实现
compiz自带的特效插件不够多,也不够强大.为了更好的体验compiz的特效,我们能够安装特效插件,在终端输入命令:sudo apt-get install compiz-plugins就能够下载特 ...
- 在webBrowser1.Navigate(url)中设置Cookie的注意点
[DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)] public static exte ...
- 【Oracle】锁
Oracle所有锁的分配和管理都是数据库管理系统自动完成的,不需要用户进行干预. v$lock表说明 字段 描述 ADDR Address of lock state object KADDR Add ...
- MyEclipse下的Debug调试技巧汇总
首先以debug模式启动tomcat,并文件中设断点,然后运行,当程序走到断点处就会转到debug视图下 [1]快捷键(F8)直接执行程序. [2]快捷键(F5)单步执行程序,遇到方法时进入. [3] ...
- 配置的好的Apache和PHP语言的环境下,如何在Apache目录下htdocs/html目录下 同时部署两个项目呢
建虚拟目录打开Apache->conf->httpd.conf在最下面粘贴NameVirtualHost 127.0.0.1 <VirtualHost 127.0.0.1> S ...