HP 35s - How to write a for loop - 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: HP 35s - How to write a for loop (/thread-14494.html) HP 35s - How to write a for loop - bxzj - 02-11-2020 05:35 PM Hi! I need to create a program to compute Euler's totient function but i'm stuck in a for loop. I have to write something like that: Code: ``` for(i = 1; i < n; i++)   // do stuff``` I'm aware of the ISG operator and the loop-control number (i.e. Code: `ccccccc.fffii` ) but i don't known how to integrate it with the i < n part. Is it possible? If so, can someone give me an example of a for loop? Thanks RE: HP 35s - How to write a for loop - Maximilian Hohmann - 02-11-2020 08:32 PM Hello! If you come from a high level programming language then programming loops and other control structures with calculators that rely on "keystroke programming" can be a very major PIA. But it is possible (to a degree). (02-11-2020 05:35 PM)bxzj Wrote:  If so, can someone give me an example of a for loop? This is an online version of the calculator manual: https://www.manualslib.com/manual/257003/Hp-35s.html?page=228#manual When you click forward two pages you can see a very simple example. Have fun with it (so to say...) Max RE: HP 35s - How to write a for loop - bxzj - 02-11-2020 08:44 PM (02-11-2020 08:32 PM)Maximilian Hohmann Wrote:  Hello! If you come from a high level programming language then programming loops and other control structures with calculators that rely on "keystroke programming" can be a very major PIA. But it is possible (to a degree). (02-11-2020 05:35 PM)bxzj Wrote:  If so, can someone give me an example of a for loop? This is an online version of the calculator manual: https://www.manualslib.com/manual/257003/Hp-35s.html?page=228#manual When you click forward two pages you can see a very simple example. Have fun with it (so to say...) Max The problem with the example provided by the manual is that it works with a “fixed limit”(for instance from 0 to 10 or from 0 to 50), what I want to do is a “dynamic” loop: something like “from 1 to x” with x inserted by the user. But I don’t know if it’s possible. RE: HP 35s - How to write a for loop - Gene - 02-11-2020 10:39 PM I think so. Simply take the user input upper limit and construct the control word. User keys 499 R/S Have the program take the 499, divide by 1000, then add one. The control word would be 1.499 and the ISG loop would repeat the steps with the variable changing from 1 to 499. If the user entered 50 or 75 or ? the loop would run from 1 to that supplied number of times. Something like this. LBL T 1E3 / 1 + STO 00 LBL L Do something in here ISG 00 GTO L STOP Is this what you are thinking about ? RE: HP 35s - How to write a for loop - bxzj - 02-12-2020 04:21 PM (02-11-2020 10:39 PM)Gene Wrote:  I think so. Simply take the user input upper limit and construct the control word. User keys 499 R/S Have the program take the 499, divide by 1000, then add one. The control word would be 1.499 and the ISG loop would repeat the steps with the variable changing from 1 to 499. If the user entered 50 or 75 or ? the loop would run from 1 to that supplied number of times. Something like this. LBL T 1E3 / 1 + STO 00 LBL L Do something in here ISG 00 GTO L STOP Is this what you are thinking about ? Exactly! thanks for your help. btw, is there any advantages to use (I)(STO 0) or (J)(STO .) registers instead of A-Z one? RE: HP 35s - How to write a for loop - Csaba Tizedes - 02-17-2020 10:20 AM Far better to use DSE instead of ISG, because no need to prepare the loop (1000 / 1 + is not required) not limited the loop end value to 999 Code: ``` LBL T   STO A   STO B   LBL L     RCL B     RCL - A     STOP     DSE A     GTO L RTN``` This is do the job also (counts from 0 to N-1). A is the counter register and B is for storing the user data to reverse the counting direction (or maybe it required later). Csaba