我是否有某种方法可以检查Python中的循环内部是否仍然存在while循环条件?像这样:
i = 0
while i < 2:
i = 2
evalcond
print("This executes because the condition is still true at this point")
这可能吗?
答案 0 :(得分:1)
或许这样的事情?
i = 0
while i < 2:
i = 2
if i >= 2:
break
print("This executes because the condition is still true at this point")
答案 1 :(得分:0)
如果您想避免使用break
,也可以执行此操作
i = 0
while i < 2:
i = 2
if i < 2:
print("This executes because the condition is still true at this point")