summaryrefslogtreecommitdiffhomepage
path: root/tests/custom/00_syntax/17_while_loop
blob: 1e68d6b0aa77f1dde2a296ef04a1e7fd6524942f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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 0
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 --