Correction about `return' usage (was: dofile question)
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Correction about `return' usage (was: dofile question)
- From: Tomas <tomas@...>
- Date: 2006年4月23日 20:22:10 -0300 (BRT)
On 2006年4月23日, 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 灣sert'
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