Marcel van Lohuizen | 75cb003 | 2019-01-11 12:10:48 +0100 | [diff] [blame] | 1 | [TOC](Readme.md) [Prev](interpolfield.md) [Next](fieldcomp.md) |
| 2 | |
Marcel van Lohuizen | af0932f | 2019-01-11 13:03:56 +0100 | [diff] [blame] | 3 | _Expressions_ |
| 4 | |
Marcel van Lohuizen | 75cb003 | 2019-01-11 12:10:48 +0100 | [diff] [blame] | 5 | # List Comprehensions |
| 6 | |
| 7 | Lists can be created with list comprehensions. |
| 8 | |
| 9 | The example shows the use of `for` loops and `if` guards. |
| 10 | |
| 11 | |
| 12 | <!-- CUE editor --> |
| 13 | ``` |
| 14 | [ x*x for x in items if x rem 2 == 0] |
| 15 | |
| 16 | items: [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ] |
| 17 | ``` |
| 18 | |
| 19 | <!-- result --> |
| 20 | ``` |
| 21 | [4, 16, 36, 64] |
| 22 | ``` |