[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: goto
- From: Roberto Ierusalimschy <roberto@...>
- Date: Tue, 20 Jul 1999 10:19:30 -0300
> It's unfortunate that 'return' has to be the last statement in a
> function, [...]
It doesn't have to. For syntactical reasons, 'return' must be the last
statement in a block, not in a function. The reason for this is that, as
Lua does not use semicolons to separate statements, a fragment like
return
print("ok")
would be interpreted as
return print("ok")
It is right to use a 'return' just before an 'end', 'else' or 'until'.
Usually these are the places where you want to use a return. Otherwise,
you can create a block just for this:
do return end
-- Roberto