in the latest version of pr33's code, the variable name is $num. So yes, I think the sqrt should be recalculated each time $num changes. In the code I had tested and bench marked earlier based on the previous version of the code proposed by pr33, the variable name was $x. And, yes, I recalculated the sqrt of $x each time $x was recalculated, but I avoided to do it within the header of the for loop, to avoid recalculating it at each iteration of the loop. In other words, I was sort of caching the value of the sqrt. This made the code a bit more complicated, but also quite faster
The latest version of pr33's code does not have a redo and is changing the loop variables within the loop, which might possibly work but is probably a bit dangerous with possible side effects. Restarting the loop with a redo is certainly less error prone.
In reply to Re^7: Avoid keeping larger lists in Memory
by Laurent_R
in thread Avoid keeping larger lists in Memory
by pr33
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |