diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2018-10-07 20:02:03 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-07 20:02:03 +0300 |
commit | 85efd363cbcbf3ac5d917a14fe1fccc857c1e859 (patch) | |
tree | f151c2b73bca3e8497c7cd9a3ee8333a14f2fa4f /docs/markdown/snippets | |
parent | 091e079354fe6322823048c9debd1a13bdc7e37f (diff) | |
parent | b6fc063b13ff53c6c36abeb592983f50da995e3b (diff) | |
download | meson-85efd363cbcbf3ac5d917a14fe1fccc857c1e859.zip meson-85efd363cbcbf3ac5d917a14fe1fccc857c1e859.tar.gz meson-85efd363cbcbf3ac5d917a14fe1fccc857c1e859.tar.bz2 |
Merge pull request #3900 from xclaesse/in-operator
Interpreter: Add "in", "not in", "break", and "continue" operators
Diffstat (limited to 'docs/markdown/snippets')
-rw-r--r-- | docs/markdown/snippets/new_syntax.md | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/docs/markdown/snippets/new_syntax.md b/docs/markdown/snippets/new_syntax.md new file mode 100644 index 0000000..98eccd0 --- /dev/null +++ b/docs/markdown/snippets/new_syntax.md @@ -0,0 +1,42 @@ +## Foreach `break` and `continue` + +`break` and `continue` keywords can be used inside foreach loops. + +```meson +items = ['a', 'continue', 'b', 'break', 'c'] +result = [] +foreach i : items + if i == 'continue' + continue + elif i == 'break' + break + endif + result += i +endforeach +# result is ['a', 'b'] +``` + +You can check if an array contains an element like this: +```meson +my_array = [1, 2] +if 1 in my_array +# This condition is true +endif +if 1 not in my_array +# This condition is false +endif +``` + +You can check if a dictionary contains a key like this: +```meson +my_dict = {'foo': 42, 'foo': 43} +if 'foo' in my_dict +# This condition is true +endif +if 42 in my_dict +# This condition is false +endif +if 'foo' not in my_dict +# This condition is false +endif +``` |