參考http://www.runoob.com/python3/python3-loop.htmlhtml
# !/usr/bin/env python3
n = 100
sum = 0
counter = 1
while counter <= n: #while循環
sum = sum + counter
counter += 1
print("1 到 %d 之和爲: %d" % (n,sum))
var = 1
while var ==1: #表達式永遠爲true
num = int(input("輸入一個數字: "))
print("你輸入的數字是: ",num)
print("Good Bye!") #使用 CTRL+C 來退出當前的無限循環
count = 0
while count <5: #while循環使用else語句,條件語句爲false時執行else語句
print(count,"小於5")
count = count +1
else:
print(count,"大於或等於5")
languages = ['c','c++','perl','python']python
for x in languages:c++
print(x)函數
for i in range(5): oop
print(i)htm
#range(3,9)指定區間的值,range(1,10,2)range以指定數字開始並指定不一樣的增量(甚至能夠是負數,有時這也叫作'步長')input