What is a proper, refined way to use a loop to execute one event an even number of times, and another an odd number of times?
I know how to generate this string using a loop:
But, if I want to generate this string, I have to alter the string outside of the loop. That is, I have to build it incorrectly then alter it. Or, I have to carry some flag into the loop from outside of it. Or, I have to feed a pre-mangled string into the loop. Over the years, I’ve used all of those methods, and I’ve been sure that there’s got to be a better way!
I get the feeling that implementations matter here, so… Off the top of my head, here are some languages that I’ve encountered this problem in… (I’m not saying that I know every nook and cranny or new development of any of these…)
Surely there is some technique available within that last one that I’m simply not aware of yet, but really, my question is more about the flow control loops found in the first three.