HP Forums
[HP50g] why this ? - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: General Forum (/forum-4.html)
+--- Thread: [HP50g] why this ? (/thread-9486.html)



[HP50g] why this ? - Gilles59 - 11-12-2017 09:19 PM

I know it's not a good idea to change the value of the counter of a "FOR NEXT" loop. But consider :

Code:

«  0.
   0. 100. FOR p
    1. 'p' STO+
    1. +
   NEXT
»

You get 50. seems logic...

Now try :

Code:
«  0.
   1. 100. FOR p
    p NEXTPRIME 'p' STO
    1. +
   NEXT
»

You get .... 1. The loop excecutes only once.
Is this a bug or I misunderstand something ?

EDIT : Ohoh ! The bug is only in approx mode ( |R ) .... NEXTPRIME always returns an integer ( 1. NEXTPRIME returns 2 and the loop dont works). With and I->R after NEXTPRIME, it's OK


RE: [HP50g] why this ? - Gerson W. Barbosa - 11-12-2017 11:16 PM

Shorter, but slower:

100

« -1, 1, ROT
DO ROT 1, + ROT NEXTPRIME ROT DUP2
UNTIL ≥
END DROP2
»

EVAL

—> 25.