Imagine I have a do loop over a variable, I. Typically this variable has a range of 1-20 but I want to create a do loop over the range 1-5 and 8-12. I can't create a simple do loop because the ranges are not consecutive. I don't want to put a logic statement in because I don't want to slow anything down. What would be a smart or creative way to execute this loop and can it be done without a logic statement?
Asked
Active
Viewed 248 times
0
-
Besides two `do` loops? – John Alexiou Feb 26 '20 at 00:08
-
You can essentially follow the approach described in answer to [this other question](https://stackoverflow.com/q/47581965/3157076): create an array with you desired indices and then select over those in the loop. Better than a `cycle`? – francescalus Feb 26 '20 at 00:10
-
Between the two linked questions you hopefully find enough to address your problem. One question's answers look at skipping iterations using logic, including modifying the "loop counter"; the other has an array to be indexed over. – francescalus Feb 26 '20 at 00:20
-
Or with `i=1,5` use `j=i+7` – John Alexiou Feb 26 '20 at 00:20