Use of Python3 goto statement

Friends who are familiar with the C language must be familiar with the goto statement, which can jump between codes at will, but many veterans have warned everyone not to use goto, because goto will make your code logic extremely confusing . But sometimes we have to use it because it's so efficient. For example, if you enter the deep layer of the loop, you can return to the top layer with a goto, and you can locate any position in the code, which is very efficient and convenient. But don't use goto for all code, then your code will become as weird as the quantum world, and you can't even control it yourself. The last piece of advice, it is best not to use goto.

 

First install a goto package (because there is no official goto statement)

pip install goto-statement

Concrete grammar

from goto import with_goto

@with_goto
def range(start, stop):
    i = start
    result = []

    label .begin
    if i == stop:
        goto .end

    result.append(i)
    i += 1
    goto .begin

    label .end
    return result

github goto pack:https://github.com/snoack/python-goto

Guess you like

Origin blog.csdn.net/yilovexing/article/details/81092388