Date: Tue, 17 Nov 2026 16:37:32 +0200
On 11/17/26 15:17, David Brown wrote:
>
> For loops are good when you are iterating over something fixed. They
> are not usually a good choice when changing the thing you are iterating
> over. Basically, if you ever feel you need to do something odd with the
> iterator that you are incrementing (or decrementing) - skipping the
> increment, repeating it, or otherwise changing its value - then "for" is
> unlikely to be the best choice of structure.
>
Arguably the overall "shape" of this loop is still a `for` loop: you
still scan the list in order, and there's still a fixed increment step
in the normal case. It's just that in the "marked" case there's a kink
(in this example that's the entire body of the loop, but you could
imagine a more complex function). It's open to interpretation though :)
>
> For loops are good when you are iterating over something fixed. They
> are not usually a good choice when changing the thing you are iterating
> over. Basically, if you ever feel you need to do something odd with the
> iterator that you are incrementing (or decrementing) - skipping the
> increment, repeating it, or otherwise changing its value - then "for" is
> unlikely to be the best choice of structure.
>
Arguably the overall "shape" of this loop is still a `for` loop: you
still scan the list in order, and there's still a fixed increment step
in the normal case. It's just that in the "marked" case there's a kink
(in this example that's the entire body of the loop, but you could
imagine a more complex function). It's open to interpretation though :)
Received on 2026-11-17 14:39:38
