Skip to content

Commit cd0d7ae

Browse files
committed
After REPI and WHILEI, the loop variable contains the number of iterations.
As pointed out by Per Austrin, the value of the loop variable after the loop was undefined. Define it to be the number of iterations, i.e. one beyond the last iteration value. Also add a modified test case provided by Per in #7.
1 parent 65cd5e6 commit cd0d7ae

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

doc/format-spec.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,17 @@ The following commands are available:
153153
times and optionally match 'separator' command (count-1) times in
154154
between. The value of count must fit in an unsigned 32 bit int.
155155
The second command 'REPI' does the same, but also stores the
156-
current iteration (counting from zero) in the variable 'i'.</dd>
156+
current iteration (counting from zero) in the variable 'i'. At the
157+
end of the loop, 'i' contains the number of iterations.</dd>
157158

158159
<dt><tt>WHILE(&lt;test&gt; condition [,&lt;command&gt; separator]) [&lt;command&gt;...] END</tt></dt>
159160
<dt><tt>WHILEI(&lt;variable&gt; i, &lt;test&gt; condition [,&lt;command&gt; separator]) [&lt;command&gt;...] END</tt></dt>
160161

161162
<dd>Repeat the commands as long as 'condition' is true. Optionally
162163
match 'separator' command between two consecutive iterations.
163164
The second command 'WHILEI' does the same, but also stores the
164-
current iteration (counting from zero) in the variable 'i'.</dd>
165+
current iteration (counting from zero) in the variable 'i'. At the
166+
end of the loop, 'i' contains the number of iterations.</dd>
165167

166168
<dt><tt>IF(&lt;test&gt; cond) [&lt;command&gt; cmds1...] [ELSE [&lt;command&gt; cmds2...]] END</tt></dt>
167169

tests/testdataloopvar.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0 1

tests/testprogloopvar.in

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# IGNORE GENERATE TESTING
2+
# Read exactly 2 bits (space-separated)
3+
WHILEI(i,!MATCH("\n"), SPACE)
4+
INT(0,1)
5+
END
6+
ASSERT(i==2)
7+
NEWLINE
8+
# Test an empty loop
9+
REPI(j,0) END
10+
ASSERT(j==0)

0 commit comments

Comments
 (0)