while循环之continue...break用法

---while循环---

import random

count = random.randint(0,10)#随机生成0~10之间数

i=0

while i<5:

  number = int(input("请输入"))

  if number<count:

    print("小了")

  elif number>count:

    print("大了")

  else:

    print("猜对了")

    break #跳出整个while循环

  i += 1

 

---continue---

i=0

while i<100:

  i += 1

  if i>10 and i<20:

    continue #跳出本次if循环,直接从第一个循环开始

  print(i)

 

posted @ 2020-03-13 17:56  打死那个龟孙  阅读(1462)  评论(0编辑  收藏  举报