The LOOP command is limited by the MXLOOPS setting in some cirumstances.
Until now, if an IF clause was present, MXLOOPS was disregarded.
However, this behavior does not match SPSS behavior. This commit makes
LOOP honor MXLOOPS even when IF is present, for compatibility.
With this commit, only the presence of an index clause makes LOOP
disregard MXLOOPS.
Thanks to Frans Houweling for reporting this bug.
loop, not at the beginning, so that the body of a loop with only a
condition on @cmd{END LOOP} will always execute at least once.
-If neither the index clause nor either condition clause is
-present, then the loop is executed @var{max_loops} (@pxref{SET}) times.
+If the index clause is not
+present, then the loop is executed at most @var{max_loops} (@pxref{SET}) times
+(but possibly fewer, if a condition clause evaluates to false or if
+@cmd{BREAK} executes).
The default value of @var{max_loops} is 40.
@cmd{BREAK} also terminates @cmd{LOOP} execution (@pxref{BREAK}).
/* If there's nothing else limiting the number of loops, use
MXLOOPS as a limit. */
- if (loop->max_pass_count == -1
- && loop->index_var == NULL
- && loop->loop_condition == NULL
- && loop->end_loop_condition == NULL)
+ if (loop->max_pass_count == -1 && loop->index_var == NULL)
loop->max_pass_count = settings_get_mxloops ();
}
])
AT_CLEANUP
+AT_SETUP([LOOP with IF condition that ends due to MXLOOPS])
+AT_DATA([loop.sps], [dnl
+LOOP_DATA
+set mxloops=3.
+compute #p = x.
+loop.
+print /x #p.
+compute #p = #p + 1.
+end loop if #p >= 6.
+print/'--------'.
+execute.
+])
+AT_CHECK([pspp -o pspp.csv loop.sps])
+AT_CHECK([cat pspp.csv], [0], [dnl
+1 1.00 @&t@
+1 2.00 @&t@
+1 3.00 @&t@
+--------
+2 2.00 @&t@
+2 3.00 @&t@
+2 4.00 @&t@
+--------
+3 3.00 @&t@
+3 4.00 @&t@
+3 5.00 @&t@
+--------
+4 4.00 @&t@
+4 5.00 @&t@
+--------
+])
+AT_CLEANUP