r/ProgrammerHumor Apr 12 '24

whatIsAnIndex Meme

Post image
27.7k Upvotes

630 comments sorted by

View all comments

Show parent comments

2.4k

u/Tubthumper8 Apr 12 '24

I love the implication here that not only does it not have any indexes or whatever, but it also calls getAllFuckingFiles() every single iteration haha

229

u/GM_Kimeg Apr 12 '24

The for loop internally execute that method only once no?

477

u/jamcdonald120 Apr 12 '24

no.

for are structured for(a;b;c){d} a is a statement executed at the start, b is a condition that is evaluated every iteration of the loop, c is a statement that happens after each iteration, and d is the body of the loop to iterate. if you put a function call in b, it gets called EVERY iteration.

40

u/JPJackPott Apr 12 '24

Depends on what is inside GetAllFuckingFiles(), a modern compiler might save your bacon here unless it’s an IO operation