softpano / pythonizer

Translator (or more correctly transcriber) from Perl to Python
http://www.softpanorama.org/Scripting/Pythonorama/Python_for_perl_programmers/Pythonizer/index.shtml
Other
39 stars 17 forks source link

next or last in block (not in loop) generates bad code #94

Open snoopyjc opened 2 years ago

snoopyjc commented 2 years ago

next or last in block (not in loop) generates bad code. Per the definition, a block that just starts with { is treated as a loop that runs once, so a next or last statement should break out of it. Instead it generates a continue or break which python flags as an error.

Also check this out: If you're in a sub {...} and that sub was called from a loop, perl lets you next or last the loop from inside the sub!!

snoopyjc commented 2 years ago

Implemented in https://github.com/snoopyjc/pythonizer v0.923. Uses exceptions. Handles breaking out of a sub if it's defined in the same file.