Slacker News Slacker News logo featuring a lazy sloth with a folded newspaper hat
  • top
  • new
  • show
  • ask
  • jobs
Library

Comment by gpderetta

1 day ago

  for(int i : some-container) {
     do-something-with(i);
  }

Where is the mutation?

2 comments

gpderetta

Reply

mrkeen  1 day ago

It's implied by void-returning do-something-with(...).

Otherwise you're just burning cycles and a good compiler should dead-code eliminate the whole loop.

(see https://news.ycombinator.com/item?id=44873488)

  • gpderetta  1 day ago

    We are discussing mutation in the loop itself, but sure:

      for(int x: container) {
          yield frob(x);
      }

Slacker News

Product

  • API Reference
  • Hacker News RSS
  • Source on GitHub

Community

  • Support Ukraine
  • Equal Justice Initiative
  • GiveWell Charities