#/usr/bin/python 
#coding=utf-8
#@Time :2017/10/18 15:31
#@Auther :liuzhenchuan
#@File :while 循环.py 示例1:
 n = 0
while True:
print 'hello world'
if n == 10:
break
n +=1
打印如下:
 hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world

示例2:

 n = 0
while True:
if n==10:
break
print n ,'hello'
n +=1

打印如下:

 0 hello
1 hello
2 hello
3 hello
4 hello
5 hello
6 hello
7 hello
8 hello
9 hello

示例3:

#条件为假的时候,也是退出循环.输入空字符的时候也退出循环
 rinput = ''
while rinput !='q':
rinput = raw_input('please input something,q is quite: ')
print 'hello'
if rinput == '':
break

示例4:

#应用逻辑非判断,退出while循环。while条件为假时,退出while循环
 rinput = ''
while rinput !='q':
rinput = raw_input('please input something,q is quite: ')
print 'hello'
if not rinput :
break

示例5:

# while...else...:正常结束while循环时会打印else后面的语句.与for...else...循环体一样
 rinput = ''
while rinput !='q':
rinput = raw_input('please input something,q is quite: ')
print 'hello'
if not rinput :
break
else:
print 'hello world'

示例6:

#while 循环嵌套if循环体,支持contine
 rinput = ''
while rinput !='q':
rinput = raw_input('please input something,q is quite: ')
print 'hello'
if not rinput :
break
elif rinput == 'quite':
continue
print 'continue'
else:
print 'hello world'


												

python 基础 2.4 while 循环的更多相关文章

  1. 『Python基础-7』for循环 & while循环

    『Python基础-7』for循环 & while循环 目录: 循环语句 for循环 while循环 循环的控制语句: break,continue,pass for...else 和 whi ...

  2. Python基础(2)——循环和分支[xiaoshun]

    一.瞎扯 世界上一切的系统都可以被'分支'表示.循环也是分支,只不过又重复之前的'分支'选择罢了.程序如人生,每一次的'分支',每一次的选择,都会有不同的结果: 有的选择止步不前,无限循环: 有的选择 ...

  3. Python基础数据类型与for循环

    数据类型:int,bool,str,list, tuple元组,dict字典. 1.数字:12,3,4 在使用print打印数字时,在终端界面中无法判断出打印的是什么类型,当我们需要知道一个值是什么类 ...

  4. Python基础之条件和循环

    阅读目录 一.if语句 1.1功能 1.2语法 1.2.1:单分支,单重条件判断 1.2.2:单分支,多重条件判断 1.2.3:if + else 1.2.4:多分支if + elif +else 1 ...

  5. Python基础7- 流程控制之循环

    循环: 把一段代码重复性的执行N次,直到满足某个条件为止. 为了在合适的时候,停止重复执行,需要让程序出现满足停止循环的条件.Python中有三种循环(实质只有两种): while循环 for循环 嵌 ...

  6. Python基础(条件判断和循环) if elif else for while break continue;

    条件判断 计算机之所以能做很多自动化的任务,因为它可以自己做条件判断. 比如,输入用户年龄,根据年龄打印不同的内容,在Python程序中,用if语句实现: age = 20 if age >= ...

  7. Python之路,Day2 - Python基础,列表,循环

    1.列表练习name0 = 'wuchao'name1 = 'jinxin'name2 = 'xiaohu'name3 = 'sanpang'name4 = 'ligang' names = &quo ...

  8. Python基础 条件判断和循环

    pyhton if 语句 if 语句后接表达式,然后用: 表示代码块. age = 20 if age >= 18: print 'your age is', age print 'adult' ...

  9. Python基础、判断、循环、列表、字典,day1

    一.Python 简介 1.介绍 Python 是一个高层次的结合了解释性.编译性.互动性和面向对象的脚本语言. Python 的设计具有很强的可读性,相比其他语言经常使用英文关键字,其他语言的一些标 ...

  10. 【Python基础】之for循环、数组字典

    一. for循环实例 1.循环字符串 Python Shell: for i in "hello": print(i) h e l l o 2.循环数组Python Shell: ...

随机推荐

  1. 关于getSystemResource, getResource 的总结

    项目中, 有时候要读取当前classpath下的一些配置文件. 之前用的读取配置文件的代码如下 public static Properties loadPropertiesFile(String f ...

  2. 慎用lodash的cloneDeep函数

    lodash的cloneDeep函数能够很方便的拷贝对象,但是一旦拷贝一些很复杂的对象就有可能报错.比如用cloneDeep克隆一个vue实例,就有可能包key.charAt is not a Fun ...

  3. scala之split()函数用法

    split()函数: def split(arg0: String): Array[String] def split(arg0: String, arg1: Int): Array[String] ...

  4. C++ STL之count函数

    谓词(predicate):是做某些检测的函数,返回用于条件判断的类型,指出条件是否成立. 总结: count : 在序列中统计某个值出现的次数 count_if : 在序列中统计与某谓词匹配的次数 ...

  5. Axure基础操作

    一  简介 Axure RP就是一个快速原型(Rapid Prototyping)设计工具. 快速原型(快速模型demo)在真正的开发之前,构造一个原型.把需求模块进行落实.实现部分交互. 二  Ax ...

  6. java JIT AOT

    作者:ETIN链接:https://zhuanlan.zhihu.com/p/27393316来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. I guess anyon ...

  7. getServletConfig().getInitParameter("count1") java.lang.NullPointerException

    通常在doget中 System.out.println(getServletConfig()); System.out.println(getServletConfig().getInitParam ...

  8. iptables 一些有用的规则

      -A INPUT -i lo -j ACCEPT #允许本机内部访问,即回环 -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT #允许 ...

  9. Python--Day2/Day3/Day4(运算符、数据类型及内建函数)

    一.昨日内容回顾 Python种类:CPython(Python).JPython.IronPython.PyPy 编码: Unicode.UTF-8.GBK while循环 if...elif... ...

  10. advanced-performance-troubleshooting-waits-latches-spinlocks

    https://www.sqlskills.com/blogs/paul/advanced-performance-troubleshooting-waits-latches-spinlocks/