for 循環用在有次數的循環上。
while循環用在有條件的循環上。
while循環,知道表達式爲假,才退出。
while循環,表達式是一個邏輯表達式,必須返回一個True或False
語法:
while expression:
statements()
#!/usr/bin/python
n = 0
while True:
if n == 10:
break
print n,'hello'
n += 1
for 循環用在有次數的循環上。
while循環用在有條件的循環上。
while循環,知道表達式爲假,才退出。
while循環,表達式是一個邏輯表達式,必須返回一個True或False
語法:
while expression:
statements()
#!/usr/bin/python
n = 0
while True:
if n == 10:
break
print n,'hello'
n += 1