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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
Two for-loop variants are supported: a C-style counting for loop
consisting of an initialization expression, a test condition
and a step expression and a for-in-loop variant which allows
enumerating properties of objects or items of arrays.
Additionally, utpl supports an alternative syntax suitable for
template block tags.
-- Expect stdout --
A simple counting for-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
Any of the init-, test- and increment expressions may be omitted.
Loop without initialization statement:
Iteration null
Iteration 1
Iteration 2
Loop without test statement:
Iteration 0
Iteration 1
Iteration 2
Loop without init-, test- or increment statement:
Iteration 1
Iteration 2
Iteration 3
For-in loop enumerating object properties:
Key: foo
Key: bar
For-in loop enumerating array items:
Item: one
Item: two
Item: three
A counting for-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
A for-in loop using the alternative syntax:
Item 123
Item 456
Item 789
-- End --
-- Testcase --
A simple counting for-loop:
{%
for (i = 0; i < 10; i++) {
print("Iteration ");
print(i);
print("\n");
}
%}
If the loop body consists of only one statement, the curly braces
may be omitted:
{%
for (i = 0; i < 10; i++)
print("Iteration ", i, "\n");
%}
Any of the init-, test- and increment expressions may be omitted.
Loop without initialization statement:
{%
for (; j < 3; j++)
print("Iteration " + j + "\n");
%}
Loop without test statement:
{%
for (j = 0;; j++) {
if (j == 3)
break;
print("Iteration ", j, "\n");
}
%}
Loop without init-, test- or increment statement:
{%
for (;;) {
if (k++ == 3)
break;
print("Iteration ", k, "\n");
}
%}
For-in loop enumerating object properties:
{%
obj = { foo: true, bar: false };
for (key in obj)
print("Key: ", key, "\n");
%}
For-in loop enumerating array items:
{%
arr = [ "one", "two", "three" ];
for (item in arr)
print("Item: ", item, "\n");
%}
A counting for-loop using the alternative syntax:
{% for (x = 0; x < 10; x++): -%}
Iteration {{ x }}
{% endfor %}
A for-in loop using the alternative syntax:
{% for (n in [123, 456, 789]): -%}
Item {{ n }}
{% endfor %}
-- End --
|