Python语句
while循环
实例:
count = 0
while (count < 9):
print('The count is:' , count)
count = count + 1
print("Good bye!")
break语句
实例:
a = 8
while a:
if a % 2 == 0:
break
else:
print("%d is add number" % a)
print("%d is even number" % a)
continue语句
实例:
a = 9
while a:
if a % 2 == 0:
a -= 1
continue
else:
print("%d is odd number" % a)
a -= 1
while else语句
实例:
count = 0
while count <5:
print(count,"is less than 5")
count = count +1
else:
print(count,"is not less than 5")
for else 语句
实例:
from math import sqrt
for n in range(99,1,-1):
root = sqrt(n)
if root == int(root):
print(n)
break
else:
print("Nothing.")