Skip to content

Comment on A function decorator that rewrites the bytecode to enable goto in Pythonparent

Comments

Lua has `goto` since 5.2; you don't need a continue keyword. e.g.

  for z=1,10 do
    for y=1,10 do
      for x=1,10 do
        if x^2 + y^2 == z^2 then
          print('found a Pythagorean triple:', x, y, z)
          print('now trying next z...')
          goto zcontinue
        end
      end
    end
    ::zcontinue::
  end

That's nicer than continue really (as someone who doesn't know and has never written Lua) - works for whichever level of nested loops like that that you want, and allows/somewhat forces you to come up with a name that might be clearer what it's for.

In Perl, "next" can take a label:

    LOOP:
    while (foo()) {
        while (bar()) {
            if (baz()) { next LOOP; }
        }
    }

Similar in Java (it is called "break", and the optional label is written the same way), although I'd guess most Java developers don't know about it.

I know we can do that, but I still want continue ;)

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.