#/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. qemu相关命令使用

    qemu-ga qemu-guest-agent-2.5.0-3.el7.x86_64 qemu-img qemu-img-1.5.3-105.el7_2.4.x86_64 qemu-io qemu- ...

  2. JS-JavaScript String 对象-string对象方法3:concat()

    1.concat():用于连接两个或多个字符串. 1).语法:string.concat(string1, string2, ..., stringX)    (string1, string2, . ...

  3. c# 扩展LINQ的order by函数支持通过字符串来指定列名并支持多列

    本文借鉴了https://blog.csdn.net/lan_liang/article/details/68523451. 将字符串转换为orderby的linq可以极大地减少重复劳动,可是该怎样将 ...

  4. Codeforces 898 A. Rounding

      A. Rounding   time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  5. java之properties和yml两种配置文件比较(非原创)

    文章大纲 一.内容介绍二.参考文章 一.内容介绍   我们在使用SpringBoot这个框架的时候都一定使用或者说是见到过application.properties或者是application.ym ...

  6. 用pid 取主窗口 hwnd

    HWND GetHwndByPid(DWORD dwProcessID) { HWND h = GetTopWindow(); HWND retHwnd = NULL; while ( h ) { D ...

  7. IDEA使用Maven打包时如何去掉测试阶段

    如图

  8. Failed to read artifact descriptor for avalon-framework:avalon-framewor

    在工程中,遇到了这个问题,百度了好久并没有满意的解决方案. 网上有一种办法是: 一.修改.m2/repository/avalon-framework/avalon-framework-api/里所有 ...

  9. 2016.11.10 Could not get JDBC Connection; nested exception is java.sql.SQLException: No suitable driver

    运行项目rds_web时,出现错误提示:Could not get JDBC Connection; nested exception is java.sql.SQLException: No sui ...

  10. maven管理整理

    maven管理整理 学习了:https://www.imooc.com/learn/443 mvn -v 版本 compile 编译 test 测试 package 打包 clean 删除 insta ...