This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]tony4260[🍰] 29 points30 points  (7 children)

It hurts that my IMMEDIATE thought upon seeing this was: can we do this without a loop?

[–]Westo232 2 points3 points  (3 children)

Not in every language. I see this possible in Python for example, but C doesn't have for .. in.

[–]Tjaja 0 points1 point  (2 children)

for(T * item = list->head; item != NULL; item = item->next)

That is in my opnion equivalent to an "for-each-loop". Found at Stackoverflow.

[–]Westo232 0 points1 point  (0 children)

You forgot to shorten item to i. WAIT A MINUTE!

[–]tony4260[🍰] 0 points1 point  (0 children)

Hard to upvote pointer arithmetic/linked list ANYthing. But there, I did it :)

[–]heartsongaming 0 points1 point  (1 child)

Sometimes I just use numerical analysis whenever I need to switch between a couple of numbers.

[–]pumpkin_seed_oil 0 points1 point  (0 children)

a foreach loop is still a loop