lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Dirk Laurie <dpl@sun.ac.za> writes:

> On Tue, Jun 14, 2011 at 03:05:24PM +0200, Jerome Vuarand wrote:
>> 2011/6/13 Roberto Ierusalimschy <roberto@inf.puc-rio.br>:
>> >> Why break can appear middle of block but not return?
>> >
>> > Because return may be followed by an optional expression. Something
>> > like 'return a       = 3' would confuse the parser.
>> 
>> But then shouldn't "return; a = 3" be allowed ?
>> 
> When?
>
> if test then return end; a=3        -- OK
> if test then return else a=3 end    -- OK
> if test then return; a=3 end        -- what's this supposed to mean?
> function x() print "gotcha!" return; a=3 end  -- never reaches a=3
>
> IMHO there is no situation in which "return; a = 3"
> can be milked into making sense.

The same would apply to "break".  The point of either is to be able to
shortcut code without deleting it from the source code for now.

-- 
David Kastrup