lua-users home
lua-l archive

Re: Assignment Expressions in Lua

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


Op 2019年7月25日 21:54:13 +0200 schreef Coda Highland <chighland@gmail.com>:
Lua's for loops don't have assignment expressions. It's actually rather
noteworthy compared to other programming languages -- neither the
initialization or the increment is a statement.
The C++17 example also looks like something I would NEVER want to write.
There's no compelling reason to put that on one line. Just kick the
initializer out to the previous line, and add braces around it if you
REALLY need the strict scoping.
/s/ Adam
You don't have to write it. :-)
What about the next example?
local function f() return false end
for i = f() and 0 or 40, 42 do
 print( i )
end
print( i )
-- Jasper

AltStyle によって変換されたページ (->オリジナル) /