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.

P#129196 2023-04-30 19:56 ( Edited 2023-04-30 19:59)

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

P#129207 2023-04-30 23:46

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.

P#129208 2023-04-30 23:54 ( Edited 2023-04-30 23:59)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-04-20 05:55:55 | 0.009s | Q:10