Log In  


The following code block prints only the number 4, though I would expect it to print 2, 3, and 4.

do
 if (false) if (true) print(1)
 print(2)
 print(3)
end
print(4)

Only the outer if has this property, the inner if's scoping is fine. Similar behavior happens without the do block, I just included it to demonstrate the interaction of this behavior with "normal" Lua scopes.

3


I think it's generally assumed that shorthand if() is intended to be one-per-line.


In that case I'd expect this to error, rather than expand the scope to the end of the current explicit block. Especially since nesting different single-line shorthand forms seems to be just fine - I can use single-line while, if, and ? together.



[Please log in to post a comment]