||
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')
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-4-30 07:22
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社