lua-users home
lua-l archive

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

On Mon, 13 Jun 2011, Roberto Ierusalimschy wrote:

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.

There's something to be said for allowing it in the middle of a block if it's followed directly by a label:

function foo ()
	return 3
	print("error1 occurred")
	return nil
	print("error2 occurred")
	return nil

In this case the expression list after return ends when you either hit end or a label.

Algol 68 has a similar construct (the value returned is the value of the last expression before END or EXIT):