1 Pages (6 items)
Using while loop rather than for loop - Messages
#1 Posted: 3/25/2021 6:21:23 AM
Hi,
Can someone help me change my for loop to a while loop?
Also, there a few uses of "programming" functions in the sheet (for loop, sums etc.). What are the best practices for use in indexes? Can I use "i" for all the programming functions, or should I use a new letter every time?
Best regards,
while loop.sm (22 KiB) downloaded 41 time(s).
Can someone help me change my for loop to a while loop?
Also, there a few uses of "programming" functions in the sheet (for loop, sums etc.). What are the best practices for use in indexes? Can I use "i" for all the programming functions, or should I use a new letter every time?
Best regards,
while loop.sm (22 KiB) downloaded 41 time(s).
#2 Posted: 3/25/2021 10:15:38 AM
while loop repeats itself as long as the condition (1st argument) it's true. So you need that it's true before the loop starts to run it at least once AND a modifier inside the loop to change it when some criterion is met.
In your example, you migth implement it like this:
![2021-03-25 14_02_55-SMath Studio - [while loop.sm_].png](/en-US/file/54Qqsh/2021-03-25-14_02_55-SMath-Studio---_while-loop_sm___png)
you can even move the i<100 check inside an infinite loop loop
![2021-03-25 14_11_50-SMath Studio - [while loop.sm_].png](/en-US/file/bHkzBx/2021-03-25-14_11_50-SMath-Studio---_while-loop_sm___png)
In your example, you migth implement it like this:
you can even move the i<100 check inside an infinite loop loop
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
#3 Posted: 3/25/2021 10:47:51 AM
Davide,
Thank you for the suggestion. The condition for continuing the loop should be (sum(PS.i))<(sum(PS.0)).
For this kind of iteration, does one make more sense over the other?
Best regards,
Thank you for the suggestion. The condition for continuing the loop should be (sum(PS.i))<(sum(PS.0)).
For this kind of iteration, does one make more sense over the other?
Best regards,
#4 Posted: 3/25/2021 5:33:20 PM
When working with while you have to focus mainly on how to stop the loop. If there is always a convergence, then you are fine. But if you get stuck in an infinite loop the program might crash. So be careful if you plan to not cap the number of iterations.
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
#5 Posted: 3/26/2021 2:25:48 PM
Are there any advantages to a while loop versus a for loop?
Do you have some tips/insight to the question regarding using the same letter over and over again in loops, sums etc.?
Best regards,
Do you have some tips/insight to the question regarding using the same letter over and over again in loops, sums etc.?
Best regards,
#6 Posted: 3/26/2021 4:17:42 PM
Wrote
1. Are there any advantages to a while loop versus a for loop?
2. Do you have some tips/insight to the question regarding using the same letter over and over again in loops, sums etc.?
............
Document would help, as you may have specific case loop.
1. Golden ratio is a self iterative While solver min/ax all at once
2. Inverse(f,L,H,N) is a simple forLoop as it invokes an auto-iterative solver
3. Critical region is a While of two variables [x,y].
Enjoy ... Jean
Golden ratio QUICK.sm (43 KiB) downloaded 43 time(s).
1 Pages (6 items)
-
New Posts
-
No New Posts