Pythonベース--breakとcountine

430 ワード

文書ディレクトリ
  • Pythonベース--breakとcountine
  • Pythonベース–breakとcountine
    breakとcontinueはループ内でのみ追加できます
    i = 1
    while i <= 5:
        print(i)
        if i == 3:
            break  #      break,         ,     
        i += 1
    print("  ")
    
    
    i = 1
    while i <= 5:
        if i == 3:
            i += 1
            continue  #      continue,                ,              
        print(i)  # 1  2  4  5
        i += 1
    print("  ")