jack0he的个人博客分享 http://blog.sciencenet.cn/u/jack0he

博文

Python-Note-2-While-loop-statements

已有 1912 次阅读 2017-4-10 21:50 |个人分类:Python 笔记|系统分类:科研笔记

While loop

while loop in Python


while condition:

   clause


Example


a=1

b=0

while a<5:

   b=a+b

   a=a+1

print('the sum is ' +str(a))

while loop in Matlab


while condition

   clause;

end


Example


a=1;

b=0;

while a<5

   b=a+b;

   a=a+1;

end

print(['the sum is ' str(a)])



Example 2

the combination of the while-loop and the input function



# function description: type your name until it equals 'your name'

name=''

while name!='your name':

   print('please type your name')

   name=input()

print('thank you')








https://wap.sciencenet.cn/blog-850613-1048022.html

上一篇:Python-Note-1-If-else-statements
下一篇:Python-Note-3-break-while-loop
收藏 IP: 80.101.95.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-4-16 18:32

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部