#/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. 常用公共DNS服务器地址

    DNS,全称Domain Name System,即域名解析系统,帮助用户在互联网上寻找路径,它在互联网的作用是把域名转换成为网络可以识别的IP地址.目前国内电信运营商通过使用DNS劫持和DNS污染的 ...

  2. TCP/IP握手协议

    转自:http://www.js123.net/t/n/n/2013/4/28/n_272.shtml 这篇介绍的也很棒:http://www.cnblogs.com/rootq/articles/1 ...

  3. CSU 1777: 大还是小?【模拟/后导0】

    293419 roniking 1777 Accepted 2032 0 C++ 2000 2018-04-03 19:21:25 Description 输入两个实数,判断第一个数大,第二个数大还是 ...

  4. addEventListener与attachEvent

    一.attachEvent和addEventListener (一)addEventListener addEventListener() 方法用于向指定元素添加事件句柄.使用 removeEvent ...

  5. poj 3140 Contestants Division [DFS]

    题意:一棵树每个结点上都有值,现删掉一条边,使得到的两棵树上的数值和差值最小. 思路:这个题我直接dfs做的,不知道树状dp是什么思路..一开始看到数据规模有些后怕,后来想到long long 可以达 ...

  6. workflow engine Ruote初体验之二(通用属性)

    罗列一下表达式所支持的属性: :timeout :if/ unless :forget :lose :flank :on_error :on_cancel :on_timeout :tag :filt ...

  7. OpenSSL使用3(基本原理及生成过程)(转)

    1. 基本原理 OpenSSL初接触的人恐怕最难的在于先理解各种概念 公钥/私钥/签名/验证签名/加密/解密/非对称加密 我们一般的加密是用一个密码加密文件,然后解密也用同样的密码.这很好理解,这个是 ...

  8. Android图片突出

    概述 今天有个群友问 Android 图片凸出 效果怎么弄,早以前有过类似的需求,整个项目的提示框都是一个背景,背景上方有凸出半张图片,所以用layer-list写了一个背景来实现. 思路 随便画了一 ...

  9. OpenCV头文件包含问题

    opencv从2.2版本以后<opencv root>include下有两个文件夹 opencv 和opencv2.从官方的意思来看,它逐渐喜欢用opencv2里面的那种包含头文件的方式. ...

  10. Could not open lock file/var/lib/dpkg/lock

    apt-get时出现错误提示: E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailabl ...