blob: 7d465fbacc088a67c8c18a07fc5d4d36866bd241 [file] [log] [blame] [view]
[TOC](Readme.md) [Prev](interpolfield.md) [Next](fieldcomp.md)
_Expressions_
# List Comprehensions
Lists can be created with list comprehensions.
The example shows the use of `for` loops and `if` guards.
<!-- CUE editor -->
_listcomp.cue:_
```
[ x*x for x in items if x rem 2 == 0]
items: [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
```
<!-- result -->
`$ cue eval listcomp.cue`
```
[4, 16, 36, 64]
```