语法:

while 判断条件:

代码块1

else:

代码块2

说明:

当判断条件为true时,执行代码块1,否则执行else后的代码块2

示例:

#!/usr/bin/python

# -*- coding: UTF-8 -*-


# 定义变量,通过赋值运算符赋值“=”

count = 0;


# 当count值小于9时输出当前count的值,count大于9后进入else部分

while count < 9:

count += 1;

print 'current is: ',count;

else:

print 'exit while';


print 'the end';

代码截图:

1-1.png

运行截图:

1-2.png

QQ截图20181031092907.png查看更多技术请移步:https://ui.29mn.com