Comment

Comment by withinboredom

> what it is about a foreach that you think would do a better job than a syntactical for-loop

It depends on the language. For example, an optimizing compiler can optimize the shit out of a for-each loop, but can only go so far in a for-loop. For example, in a for-loop, you can "skip around" the indices, and even go backward after going forward, while in a for-each loop, it will always go one-by-one, and the compiler can rely on that fact. Even the CPU can probably optimize it better since the data access will be more predictable.

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton