我有可能有無限循環的代碼。我希望能夠在代碼中阻止它,有沒有什麼可以做到的?有些東西,如:Python,預測無限循環
for i to range(0,5):
timer = on
run(x)
#while run is running
if timer.time > 30:
exit run(x)
print("out of time ")
print(timer.time)
所以輸出可能是:3,2,出來的時候30,2,出來的時候30
恐怕這可能需要線程,這是我在嘗試C和Java,學校,但從來沒有蟒蛇。
你的意思是像[破](http://docs.python.org/2/tutorial/controlflow.html#break-and - 繼續語句,和其他子句-ON-循環)? – Mariano
不,因爲我不想跳出for循環,只是迭代運行(x) – EasilyBaffled
@ F3AR3DLEGEND:它顯然是僞代碼。 – nneonneo