我有安装goto的问题,但我也不确定我是否想在我的代码中使用它,所以如果在内部而真正的无限循环我想回到某个点,条件下面的某个地方循环,如何在python中弄清楚它?
这里是一个内部结构,而真正的无限循环,如果我可以得到它没有goto
x = 0
#some code
a + b # just some place in code, which must be return point if further condition is true
if x > 0: # if x is not 0 make it 0
x = (x == 0)
#some code
if y == 1: # some result to make further condition true
x = (x + 1)
if x == 1:
# and here if I have this condition from above go to a + b and start from there
#some code
答案 0 :(得分:2)
您可以使用while True
加continue
和break
获得该行为。无需模块。
x = 0
#some code
while True:
a + b # just some place in code, which must be return point if further condition is true
if x > 0: # if x is not 0 make it 0
x = (x == 0)
#some code
if y == 1: # some result to make further condition true
x = (x + 1)
if x == 1:
# and here if I have this condition from above go to a + b and start from there
continue
break
#some code
编辑:功能
def other_function():
a = 1
while True:
# some code
if a == b:
continue
# some more code
if sin(a) < sqrt(a**2 + b**2):
break:
# more code
# still more code
def main():
# some code
while True:
# some more code
other_function()
# still more code
# after a while
exit(0)