Post Reply 
Bug in nested loop CAS break/continue [n]
11-19-2018, 10:31 PM (This post was last modified: 11-20-2018 06:37 AM by Laka.)
Post: #1
Bug in nested loop CAS break/continue [n]
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
Find all posts by this user
Quote this message in a reply
11-20-2018, 06:32 AM
Post: #2
RE: Bug in nested loop CAS break/continue [n]
There is no support for this kind of break/continue inside the CAS.
Find all posts by this user
Quote this message in a reply
11-20-2018, 06:53 AM
Post: #3
RE: Bug in nested loop CAS break/continue [n]
(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?
Find all posts by this user
Quote this message in a reply
11-22-2018, 08:14 AM
Post: #4
RE: Bug in nested loop CAS break/continue [n]
(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?

Tom L
I think therefore I am-Descartes
I think therefore you are-Gorgias
You're not here to think-Army Sergeant
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)