Post Reply 
[HP50g] why this ?
11-12-2017, 09:19 PM (This post was last modified: 11-12-2017 09:34 PM by Gilles59.)
Post: #1
[HP50g] why this ?
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
Find all posts by this user
Quote this message in a reply
11-12-2017, 11:16 PM
Post: #2
RE: [HP50g] why this ?
Shorter, but slower:

100

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

EVAL

—> 25.
Find all posts by this user
Quote this message in a reply
Post Reply 




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