_hyperscript icon indicating copy to clipboard operation
_hyperscript copied to clipboard

"classical" for loops?

Open rozek opened this issue 3 years ago • 0 comments

I must have missed s.th. - or I am blind - but

how do I implement "classical" for-loops such as

for i from <start> to <stop> by <step>

e.g.,

for i from 1000 to 1000000

I know that there is

repeat for i in [...]

but I really can't create a literal list with thousands or even more elements - and creating it programmatically would, again, require a classical for-loop...

Right now, I know of two approaches (not taking into account that <stop> could be less than <start> and <step> could be different from 1)

repeat (<stop>-<start>+1) times index i
  set i to i+<start>-1
  ...
end

and

set i to <start>
repeat while (i <= <stop>)
  ...
  increment i
end

but both of them are error-prone and far from being readable.

Thus: what's the recommended alternative?

rozek avatar Jul 26 '22 06:07 rozek