[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Added `continue` keyword to Lua 5.4 [code review requested].
- From: Paul Ducklin <pducklin@...>
- Date: Sat, 18 Mar 2023 12:28:46 +0000
>This should really help to reduce
>unnecessary if-statement nesting
If history is a good guide (given the number of times this has been discussed before), you can be pretty certain that ‘continue’ will never come to Lua, so your patch will be forever non-standard.
Therefore any of your code that uses it will require your users to download “your” Lua variant, or to experience compile-time disappointment if they try to run it with a standard version of Lua they’ve already got on their system.
Just put a label at the end of your loop (you can even call it ::continue:: if you like) and use a forward goto. Problem solved.
Or code the loop body as a nested function and return from it whenever you want to skip evaluation early in an iteration.
The nice thing about Lua is that its compact grammar and implementation means you can easily modify it to be more like some other language you already know and like.
The other nice thing about Lua is that you almost always find you don’t need to, and that you might as well stick both to the spirit *and* the letter of the PUC-Rio implementation.