Post Reply 
IF THEN Command question
12-15-2013, 09:52 PM
Post: #1
IF THEN Command question
From Page 531, 532 Prime User Manual
EXPORT ISPERFECT(n)
BEGIN
LOCAL d, sum;
2 ▶ d;
1 ▶ sum;
WHILE sum <= n AND d < n DO
IF irem(n,d)==0 THEN
sum+d ▶ sum;
END;
d+1 ▶ d;
END;
RETURN sum==n;
END;
The following program displays all the perfect numbers up
to 1000:
EXPORT PERFECTNUMS()
BEGIN
LOCAL k;
FOR k FROM 2 TO 1000 DO
IF ISPERFECT(k) THEN
MSGBOX(k+" is perfect, press OK");
END;
END;
END;

In the above bolded text, how is the test being performed? In HP50 RPL, it would be tested against a value in level 1 of the stack, but this appears to be an algebraic test. Thanks
rcf
Find all posts by this user
Quote this message in a reply
12-15-2013, 10:48 PM
Post: #2
RE: IF THEN Command question
If <returning result from things here is not 0> then ...

My website: ried.cl
Visit this user's website Find all posts by this user
Quote this message in a reply
12-15-2013, 11:04 PM
Post: #3
RE: IF THEN Command question
Prime use
0 as False
non 0 as True
So IF Myfunc(n) THEN ... END; is like
IF Myfunc(n) <> 0 THEN ... END;

Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
Find all posts by this user
Quote this message in a reply
12-16-2013, 12:22 AM
Post: #4
RE: IF THEN Command question
Thanks Eried and Patrice. That answered my question.
rcf
Find all posts by this user
Quote this message in a reply
Post Reply 




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