diff options
author | Jo-Philipp Wich <jo@mein.io> | 2020-09-08 21:19:06 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2020-09-08 21:19:06 +0200 |
commit | c77a5bebc9ae8df17b851b6256cb42fa5d763dba (patch) | |
tree | 77c7dac828ad7ef8bad17972f2a256ac632fbea3 /tests/00_syntax/17_while_loop | |
parent | c735882bb492ff81f98773186652dbe878ff3d60 (diff) |
tests: add further arithmetic and syntax test cases
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'tests/00_syntax/17_while_loop')
-rw-r--r-- | tests/00_syntax/17_while_loop | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/tests/00_syntax/17_while_loop b/tests/00_syntax/17_while_loop new file mode 100644 index 0000000..6d6dc4a --- /dev/null +++ b/tests/00_syntax/17_while_loop @@ -0,0 +1,74 @@ +Utpl implements C-style while loops which run as long as the condition +is fulfilled. + +Like with for-loops, an alternative syntax form suitable for template +blocks is supported. + + +-- Expect stdout -- +A simple counting while-loop: +Iteration 0 +Iteration 1 +Iteration 2 +Iteration 3 +Iteration 4 +Iteration 5 +Iteration 6 +Iteration 7 +Iteration 8 +Iteration 9 + + +If the loop body consists of only one statement, the curly braces +may be omitted: +Iteration 0 +Iteration 1 +Iteration 2 +Iteration 3 +Iteration 4 +Iteration 5 +Iteration 6 +Iteration 7 +Iteration 8 +Iteration 9 + + +A counting while-loop using the alternative syntax: +Iteration null +Iteration 1 +Iteration 2 +Iteration 3 +Iteration 4 +Iteration 5 +Iteration 6 +Iteration 7 +Iteration 8 +Iteration 9 + +-- End -- + +-- Testcase -- +A simple counting while-loop: +{% + i = 0; + while (i < 10) { + print("Iteration "); + print(i); + print("\n"); + i++; + } +%} + +If the loop body consists of only one statement, the curly braces +may be omitted: +{% + i = 0; + while (i < 10) + print("Iteration ", i++, "\n"); +%} + +A counting while-loop using the alternative syntax: +{% while (x < 10): -%} +Iteration {{ "" + x++ }} +{% endwhile %} +-- End -- |