lua-users home
lua-l archive

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


> Since we are talking about this, I should say I never understood why
> return really needs to be at the end of a block. Lua 5.0 required that
> for break and return, now it is not required for break. Lua 5.0 did
> not have goto, Lua 5.4 does, and it is not required to be the last
> statement in the block. So it looks like return is the only
> transfer-of-control statement that has this requirement, the other
> such statements do not have the requirement, or it has been lifted.
> Why not return, too?

It is a source of syntax ambiguity. Compare
    return;
    print("unreachable code")

with 
    return
    print("unreachable code")

Return is the only of the three that has something optional after
it. Gotos always have exactly one ID after them, so there is no
ambiguity.

Breaks followed that rule to keep open the possibility of labeled
breaks.  After goto, we gave up the idea of labeled breaks, but now I
particularly would prefer that all of them (break/return/goto) followed
this rule.

-- Roberto