count = 0
phrase = "hello, world"
for iteration in range(5): #iterate 5 times
while True:
#count = count + len(phrase)
count += len(phrase) # add the length of phrase to current value of count.
break # break out of while loop, while loop
# runs only once for each iteration
#print the value of current count
print("Iteration " + str(iteration) + "; count is: " + str(count))
所以,简而言之,程序的长度增加了phrase
5count
倍。
输出:
Iteration 0; count is: 12 # 0+12
Iteration 1; count is: 24 # 12+12
Iteration 2; count is: 36 # 24+12
Iteration 3; count is: 48 # 36+12
Iteration 4; count is: 60 # 48+12
上面的程序大致相当于:
count = 0
phrase = "hello, world"
for iteration in range(5):
count = count + len(phrase)
print("Iteration " + str(iteration) + "; count is: " + str(count))