[clue-tech] increment weather

David L. Anselmi anselmi at anselmi.us
Mon Feb 22 23:05:11 MST 2010


David L. Willson wrote:
> I have a loop-counter that I want to increment from within the loop, having found that the next
> two items in the array I'm iterating through belong to me.  How can I do that?
>
> This illustrates my problem:
>
> for i in $(seq 10)

What Dennis said.  Your i isn't a loop counter, it's a list iterator that gets assigned at the 
beginning of each pass.  Compare to:

for i in foo bar baz

I think in PHP there's an indexer that you can tweak on arrays but I don't think so in shell.

But even on Dennis's form (or Jed's while loop, which is essentially the same) I wonder whether 
in-loop mods are a good idea.  Remember what Kernighan said about debugging being harder than coding...

Dave


More information about the clue-tech mailing list