1. 程式人生 > >【課程10】迴圈語句與註釋

【課程10】迴圈語句與註釋

while迴圈

#當某個條件成立後,持續迴圈
#while 條件:
#迴圈語句(迴圈體)
'''
def sumSum(star,end,step):
i = star
sum = 0
while i<=end:
sum += i
i += step
return sum
print(sumSum(1,10,1))
'''
#死迴圈,記憶體填充,監控異常等用處
'''
while True:
pas = input('請輸入密碼:')
if pas == '123':
print('輸入密碼正確!')
break
print('你輸入的密碼錯誤!')
'''

for迴圈

#for迴圈
nameList = ['milk','jack','mary']
index = 0
while index < len(nameList):
print(nameList[index])
index += 1
print('for迴圈:')
for name in nameList:#遍歷迴圈
print(name)
for name in range(0,len(nameList)):
print(nameList[name])
for one in range(1,10):#遍歷迴圈數值
print(one)

break語句

跳出本層迴圈語句!

continue語句

結束本次迴圈!

註釋

#、‘’‘內容’‘’、ctrl+/

def sum():
'''
備註資訊
'''
return 1
print(sum.__doc__)