Comprehension

myNums = [1, 90, 50, 32]
mySquared = (num**2 for num in myNums)

for i in mySquared:
    print(i)

is valid code now even after compiling to Luau.

local myNums = {1, 90, 50, 32}
local mySquared = (function() local result = {} for num in myNums do table.insert(result, (num ^ 2)) end return result end)()
for i in mySquared do
    print(i)
end

Dictionary and List comprehension is also supported.

Last updated