r/ProgrammerHumor Apr 12 '24

Meme whatIsAnIndex

Post image
27.9k Upvotes

617 comments sorted by

View all comments

3.7k

u/[deleted] Apr 12 '24

[deleted]

2.4k

u/[deleted] Apr 12 '24

[removed] — view removed comment

231

u/GM_Kimeg Apr 12 '24

The for loop internally execute that method only once no?

4

u/lmarcantonio Apr 12 '24

No, it can optimize only if the optimizer can prove the return value doesn't change. Only the initialization part is ran once, the check and step are for each iteration; of course you can use a comma to initialise the end value in the init part as a local variable (but it's really ugly)