程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Continue and break of Python

編輯:Python

python And continue、 break

Simulation conditions :

  • Through nested loops ,5 floor Each layer 8 A room Your room number, L1-101, Cycle through each room number
  • The third floor is under renovation Skip the third floor interview
  • 404 There is an emergency in the room The road in the back room is blocked, so I won't interview

Code post :

for i in range(1,6):
print(f"-----------{
i} layer ----------")
if i == 3:
print("3 The building is under decoration .....")
continue #---------------------------- Skip this cycle So let's do the next loop 
for j in range(1,9):
if i==4 and j==4:
print(" Something unexpected happened ......")
break #---------------------------- End the current cycle 
print(f"L{
i}-{
i}0{
j} room ")

Execution results :


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved