1.whlie循环
i = 1
while i <= 100:
print(f"第{i}次")
i += 1
j = 1
sum = 0
while j <= 100:
# sum = sum + j
sum += 1
j += 1
print(sum)
'''
第一次循环 j = 1, sum=0, --> sum = sum + j = 0 + 1 = 1, sum = 1, j = 2
第二次循环 sum = 1, j = 2, --> sum = sum + j = 1 + 2 = 3, sum = 3, j = 3
第三次循环 sum = 3, j = 3, --> sum = sum + j = 3 + 3 = 6, sum = 6,j=4
...
第九十九次循环 sum =4851 ,j = 99, --> sum + j = 4851 + 99 = 4950, sum=4950, j = 100
第一百次循环 sum = 4950, j = 100, --> sum + j = 4950 + 100 = 5050,sum = 5050, i = 101
第101次循环 不满足条件结束循环
'''
2.break终止循环
# 吃四个苹果
i = 1
while i <= 4:
print(f"吃第{i}个苹果")
i += 1
print("=================")
# 吃四个苹果 吃到第三个就吃饱了,不用吃第四个了
i = 1
while i <= 4:
print(f"吃第{i}个苹果")
if i == 3:
print("我吃饱了,毁灭吧,我累了")
# 终止所有循环 跳出循环
break
i += 1
prin