HP Forums
this short program crashes my PRIME - 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: this short program crashes my PRIME (/thread-142.html)



this short program crashes my PRIME - Marek Russ - 12-18-2013 12:06 AM

Code:

EXPORT ELODIFF(R)
BEGIN
LOCAL LI,I,A,B,C;
LI:={
{0,3,0.5},{4,10,0.51},{11,17,0.52},
{18,25,0.53},{26,32,0.54},{33,39,0.55},
{40,46,0.56}
};
FOR I FROM 1 TO SIZE(LI) DO
A:=LI(I,1);
B:=LI(I,2);
C:=LI(I,3);
 IF ((R≥A)  AND (R≤B)) THEN
  RETURN (C);
  KILL;
 END;
END;
RETURN 0;
END;

First time it returns right answer, e.g.:
ELODIFF(15)=.52 //this what I need
Second time I get:
ELODIFF(15)=15 //something gets wrong...
After several callings with different arguments my HP PRIME CRASHES...


RE: this short program crashes my PRIME - Michael de Estrada - 12-18-2013 03:11 AM

I think you may be confusing things by enclosing the returned variable C in parentheses. Try just RETURN C;


RE: this short program crashes my PRIME - Namir - 12-18-2013 06:14 AM

I think the problem is with using SIZE in the FOR Loop. SIZE returns a list and not a scalar. You should assign the result of SIZE to a list first and then access the first element of that list as the upper loop limit.

Namir


RE: this short program crashes my PRIME - Michael de Estrada - 12-18-2013 06:28 AM

(12-18-2013 06:14 AM)Namir Wrote:  I think the problem is with using SIZE in the FOR Loop. SIZE returns a list and not a scalar. You should assign the result of SIZE to a list first and then access the first element of that list as the upper loop limit.

Are you sure ? According to the Prime Help for SIZE, it accepts a list as the input and returns a scalar representing the number of element in the list, so for this program it should be 7.

I just checked it out and it does works that way, so for example SIZE({{1,2,3},{4,5,6},{7,8,9},{10}}) returns 4.


RE: this short program crashes my PRIME - cyrille de brébisson - 12-18-2013 07:35 AM

Hello,

Not your fault... There is a bug in the return call in the for loop which is causing the issue...
a workaround while waiting for the fix is to copy your 'output' in a variable (C will work) and then to do a break; to exit from the for loop...
then return your C....

note, you can do:
if A<=R<=B then break; end;
this should work

Cyrille


RE: this short program crashes my PRIME - Marek Russ - 12-18-2013 08:20 AM

Thank you Cyrille, now it works!