循环

1.死循环

while 1==1:

  print()

 

 

2.while  else

while 条件:

  print()

else :

  print()

3.continue   跳过本次循环 ,进行下一轮循环

4.break 结终止所有循环

 

n=1
while n < 11:
    if n == 7:
        pass
    else:
         print(n)
    n+=1
n = 1
sum = 0
while n < 101:
    sum = sum + n
    n += 1
print(sum)
n = 1
while n < 101:
    if n % 2 == 1:
        print(n)
    n += 1
n = 1
while n < 101:
    if n % 2 == 0:
        print(n)
    n += 1
n = 1
sum = 0
while n < 100:
    temp = n % 2
    if temp == 0:
        sum = sum - n
    else:
        sum = sum + n
    n = n + 1
print(sum)

 

 

posted @ 2019-07-28 23:48  暖o0兮  阅读(110)  评论(0编辑  收藏  举报