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...
I think you may be confusing things by enclosing the returned variable C in parentheses. Try just RETURN C;
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
(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.
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
Thank you Cyrille, now it works!