Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

วิธีใช้ Else Statement กับ Loops ใน Python

Else Block ถูก Execute หลัง Iterations และก่อน Program Control ออกจาก Loop Block

x = 0
while x < 5:
    x = x + 1
    print(x)
else:
    print("else block of loop")
print("loop is over")