mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
Update syntax-list-comprehensions.md
This commit is contained in:
parent
fb1c5c2f1e
commit
17c0462665
1 changed files with 16 additions and 0 deletions
|
@ -15,6 +15,22 @@ To solve these problems, I propose a `n for-in-do` expression form that is synta
|
||||||
|
|
||||||
The `n for-in-do` expression must match ``<identifier> for <identifier> in <expr> do``
|
The `n for-in-do` expression must match ``<identifier> for <identifier> in <expr> do``
|
||||||
|
|
||||||
|
Example:
|
||||||
|
```lua
|
||||||
|
-- normal
|
||||||
|
local t = {1,2,3,4,5,6,7,8,9}
|
||||||
|
local onlyEven = {}
|
||||||
|
for i,n in pairs(t) do
|
||||||
|
if n%2 == 0 then
|
||||||
|
table.insert(onlyEven, n)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- list comprehensions
|
||||||
|
local t = {1,2,3,4,5,6,7,8,9}
|
||||||
|
local onlyEven = {local n for n in t do if n%2 == 0 then n}
|
||||||
|
```
|
||||||
|
|
||||||
## Drawbacks
|
## Drawbacks
|
||||||
|
|
||||||
List comprehensions may be misused.
|
List comprehensions may be misused.
|
||||||
|
|
Loading…
Add table
Reference in a new issue