From: Ben Pfaff Date: Sat, 5 Nov 2011 23:11:59 +0000 (-0700) Subject: LOOP: Correctly implement MXLOOPS and add a test. X-Git-Tag: v0.7.9~109 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=681bd9eab15d80bf2e424033a249f54548b342f4;p=pspp-builds.git LOOP: Correctly implement MXLOOPS and add a test. Previously the MXLOOPS value was implemented incorrectly: the loop would actually iterate MXLOOPS+1 times. This commit fixes the problem. --- diff --git a/src/language/control/loop.c b/src/language/control/loop.c index e91d9438..e4877b9e 100644 --- a/src/language/control/loop.c +++ b/src/language/control/loop.c @@ -367,12 +367,8 @@ end_loop_trns_proc (void *loop_, struct ccase **c, casenumber case_num UNUSED) goto break_out; /* MXLOOPS limiter. */ - if (loop->max_pass_count >= 0) - { - if (loop->pass >= loop->max_pass_count) - goto break_out; - loop->pass++; - } + if (loop->max_pass_count >= 0 && ++loop->pass >= loop->max_pass_count) + goto break_out; /* Indexing clause limiter: counting downward. */ if (loop->index_var != NULL) diff --git a/tests/language/control/loop.at b/tests/language/control/loop.at index af8d8aec..be214cce 100644 --- a/tests/language/control/loop.at +++ b/tests/language/control/loop.at @@ -208,10 +208,9 @@ AT_CHECK([cat pspp.csv], [0], [dnl ]) AT_CLEANUP -AT_SETUP([LOOP with no conditions]) +AT_SETUP([LOOP with no conditions containing BREAK]) AT_DATA([loop.sps], [dnl LOOP_DATA -set mxloops = 2. compute #p = x. loop. print /#p. @@ -246,3 +245,43 @@ AT_CHECK([cat pspp.csv], [0], [dnl -------- ]) AT_CLEANUP + +AT_SETUP([LOOP with no conditions that ends due to MXLOOPS]) +AT_DATA([loop.sps], [dnl +LOOP_DATA +set mxloops=2. +loop. +compute #p = #p + 1. +print /x #p. +end loop. +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@ + +-------- + +2 3.00 @&t@ + +2 4.00 @&t@ + +-------- + +3 5.00 @&t@ + +3 6.00 @&t@ + +-------- + +4 7.00 @&t@ + +4 8.00 @&t@ + +-------- +]) +AT_CLEANUP +