程序流程控制

分支语句

  • if
  • if-else
  • if-elif-else
  1. if missYou:
  2. print("I miss you.")
  3. else:
  4. print("I don't miss you.")

循环语句

  • while

遇到break、return、异常,循环会终止。

  1. while missYou:
  2. print("I miss you.")
  3. missYou=False
  4. else:
  5. print("ELSE.")
  • for
  1. for item in items:
  2. print(item)
  3. else:
  4. print("ELSE.")
  5. for item in range(1,10):
  6. print(item) # 输出1-9

跳转语句

  • break
  • continue
  • return