cdjc / goto

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error in global label

jiamo opened this issue · comments

from goto import *


@goto
for i in range(1, 10):
    for j in range(1, 20):
        for k in range(1, 30):
            print (i, j, k)
            if k == 3:
                goto .end
label .end

print ("Finished\n")



    engine@engine:~/Git/goto$ python3 test_goto1.py 
  File "test_goto1.py", line 7
    for i in range(1, 10):
      ^
SyntaxError: invalid syntax

By the way python2 is not support?

commented

The goto module provides a function decorator. You must apply it to a function. So you could change your example to be like so:

from goto import *

@goto
def jiamo():
    for i in range(1, 10):
        for j in range(1, 20):
            for k in range(1, 30):
                print (i, j, k)
                if k == 3:
                    goto .end
    label .end

    print ("Finished\n")

jiamo()

And no, there is no python 2 support.