Hacker News new | ask | show | jobs
by backslash_16 2240 days ago
If I have read his example correctly - he's not modifying the object he is looping over. car_ids is externally defined and he is using a loop to exhaustively test other objects and take an action on them, which is adding them to the externally defined array.

I do agree with what you are saying, don't modify the enumerable you loop over. IIRC C# is pretty safe in that it doesn't allow modifications to the enumerable inside of a for loop or foreach loop.

I think it's interesting people say functional constructs like map don't involve looping. They do, it's just hidden from the caller of those functions.