HP Forums
Bug in nested loop CAS break/continue [n] - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: Bug in nested loop CAS break/continue [n] (/thread-11825.html)



Bug in nested loop CAS break/continue [n] - Laka - 11-19-2018 10:31 PM

Hey guys, just trying to contribute a bit. I really do like my HP Prime but have recently found an issue.

When using the break or continue statements in both Home and CAS modes, nested loops will show the same effect, e.g. when you use this in home mode:
Code:
export TestContHome()
begin
  local a, b;
  for a from 1 to 3 do
    for b from 1 to 3 do
      if even(b) then CONTINUE; end;
      print("a="+a+","+"b="+b);
    end;
  end;
end;

Or, the same in CAS mode:
Code:
#cas
TestContCAS():=
begin
  local a, b;
  for a from 1 to 3 do
    for b from 1 to 3 do
      if even(b) then CONTINUE; end;
      print("a="+a+","+"b="+b);
    end;
  end;
end;
#end

You will get the same result:
Code:
a=1,b=1
a=1,b=3
a=2,b=1
a=2,b=3
a=3,b=1
a=3,b=3

But if you use the optional [n] parameter to break out to the the outer loop, the result is different. Try replacing the continue statement like this (to get you to the outer level):
Code:
      if even(b) then CONTINUE 2; end;

In Home mode, the result is as expected, bypassing the inner loop:
Code:
a=1,b=1
a=2,b=1
a=3,b=1

But in CAS mode, this CONTINUE statement is totally ignored, giving this output:
Code:
a=1,b=1
a=1,b=2
a=1,b=3
a=2,b=1
a=2,b=2
a=2,b=3
a=3,b=1
a=3,b=2
a=3,b=3

This applies both to BREAK and CONTINUE, so I am suspecting a CAS bug.

Just to clarify, when using BREAK 2 instead of CONTINUE 2, in Home mode you will get:
Code:
a=1,b=1
In CAS mode you will get:
Code:
a=1,b=1
a=2,b=1
a=3,b=1

I am running Build 2.1.14181.

Maybe I am overlooking something, but I would really like to know.

Regards,
Dag


RE: Bug in nested loop CAS break/continue [n] - parisse - 11-20-2018 06:32 AM

There is no support for this kind of break/continue inside the CAS.


RE: Bug in nested loop CAS break/continue [n] - Laka - 11-20-2018 06:53 AM

(11-20-2018 06:32 AM)parisse Wrote:  There is no support for this kind of break/continue inside the CAS.

I realize that this is not a problem with the CAS itself, but that the HP Prime is executing differently in CAS mode compared to Home mode. And there is no problem to code around this when you are aware. But where are these differences documented?


RE: Bug in nested loop CAS break/continue [n] - toml_12953 - 11-22-2018 08:14 AM

(11-20-2018 06:32 AM)parisse Wrote:  There is no support for this kind of break/continue inside the CAS.

So shouldn't it give a syntax error or something in CAS mode?