何代杰
Python-Note-2-While-loop-statements
2017-4-10 21:50
阅读:1941

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://m.sciencenet.cn/blog-850613-1048022.html?mobile=1

收藏

分享到:

当前推荐数:0
推荐到博客首页
网友评论0 条评论
确定删除指定的回复吗?
确定删除本博文吗?