Skip to content

Commit

Permalink
After REPI and WHILEI, the loop variable contains the number of itera…
Browse files Browse the repository at this point in the history
…tions.

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.
  • Loading branch information
eldering committed Nov 19, 2018
1 parent 65cd5e6 commit cd0d7ae
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
6 changes: 4 additions & 2 deletions doc/format-spec.md
Expand Up @@ -153,15 +153,17 @@ The following commands are available:
times and optionally match 'separator' command (count-1) times in
between. The value of count must fit in an unsigned 32 bit int.
The second command 'REPI' does the same, but also stores the
current iteration (counting from zero) in the variable 'i'.</dd>
current iteration (counting from zero) in the variable 'i'. At the
end of the loop, 'i' contains the number of iterations.</dd>

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

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

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

Expand Down
1 change: 1 addition & 0 deletions tests/testdataloopvar.in
@@ -0,0 +1 @@
0 1
10 changes: 10 additions & 0 deletions tests/testprogloopvar.in
@@ -0,0 +1,10 @@
# IGNORE GENERATE TESTING
# Read exactly 2 bits (space-separated)
WHILEI(i,!MATCH("\n"), SPACE)
INT(0,1)
END
ASSERT(i==2)
NEWLINE
# Test an empty loop
REPI(j,0) END
ASSERT(j==0)

0 comments on commit cd0d7ae

Please sign in to comment.