lua-users home
lua-l archive

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


On Sun, 23 Apr 2006, Shmuel Zeigerman wrote:

return doesn't have to be the last statement but it has to be "top-level" that is, not inside some function.
	`return' has to be the last statement.  For example:

f=assert(loadstring"return 1; print(2)")
stdin:1: [string "return 1; print(2)"]:1: <eof> expected near `print'
stack traceback:
        [C]: in function āssert'
        stdin:1: in main chunk
        [C]: ?

	Quoting the manual (5.1):

The return and break statements can only be written as the last statement of a block. If it is really necessary to return or break in the middle of a block, then an explicit inner block can be used, as in the idioms `do return endī and `do break endī, because now return and break are the last statements in their (inner) blocks.

	Tomas