Python 3.x 如何回到无限循环中的某一点

Python 3.x 如何回到无限循环中的某一点,python-3.x,Python 3.x,我对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

我对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

您可以使用
break
获得该行为,而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)
def other_函数():
a=1
尽管如此:
#一些代码
如果a==b:
持续
#还有代码吗
如果sin(a)
您可以使用
获得该行为,而True
加上
继续
中断
。不需要模块

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)
def other_函数():
a=1
尽管如此:
#一些代码
如果a==b:
持续
#还有代码吗
如果sin(a)
我不知道你在问什么。但是标准python中没有
goto
。你的意思是说乌龟。去吧?或者可能是模块?是的,转到模块,但我在安装上有问题,可能是因为没有转到,我编辑了这篇文章来展示我想要的。我不确定你在问什么。但是标准python中没有
goto
。你的意思是说乌龟。去吧?或者可能是模块?是的,转到模块,但我在安装上有问题,可能是因为没有转到,我编辑了帖子来展示我想要的东西。如果我这样做的话,我尝试了块,但里面有异常。所有内容都在main中,而真正的无止境循环则在main中,因此代码的选定部分正是以这种方式工作的,即在块之间使用break和continue,更精确地说,但在某些地方现在很难以这种方式使用它。然后将属于一起的部分代码放入单独的函数中,以更好地构造代码。您还可以将循环的其余部分放入if子句中,并且仅在goto条件不为true时运行它。您能否为我演示一些简单的示例,其中包含此情况下的函数Hello,我尝试了其中的异常块,如果我这样做,则返回true。所有内容都在main中,而真正的无止境循环则在main中,因此代码的选定部分正是以这种方式工作的,即在块之间使用break和continue,更精确地说,但在某些地方现在很难以这种方式使用它。然后将属于一起的部分代码放入单独的函数中,以更好地构造代码。您还可以将循环的其余部分放在if子句中,并且仅在goto条件不为true时运行它。您能为我演示一些简单的示例,其中包含用于此情况的函数吗