循环
# 循环语句包含了while循环和for循环
i = 10
while i != 0:
print(f'i = {i}')
i -= 1
# i = 0 cannot be printed
累加
# 高斯公式
i = 0
sum = 0
while i <= 100:
sum = sum + i
i += 1
print(sum)
sum = (1 + 100) * 100 / 2
print(sum)
sum = i = 0
while i <= 100:
if i % 2 == 0:
sum += i
i += 1
print(sum)
# python has no i++
break
break直接跳出当前循环
continue
continue直接跳过下面的语句,重新进行循环
九九乘法表
# 九九乘法表
i, j = 0, 0
while i < 9:
i += 1
while j < i:
j += 1
print(f'{i} * {j} = {i*j}\t', end="")
j = 0
print(end="\n")