2 ms·
I didn't know that whiles were less normal than fors. And though I don't object to for loops in this situation, I really had to puzzle yours out, because of th
by adrianratnapala 10y ago
I didn't know that whiles were less normal than fors.
And though I don't object to for loops in this situation, I really had to puzzle yours out, because of the way your loop pointer is one behind the place of interest.
I believe you when you say it is segfault-free, but again I would have to puzzle at the code to be sure.
- akkartik 10y agoI think I'd be ok with a `while` that looked like this: while (prev->next) { if (prev->next == entry) break; prev = prev->next; } or even this: while (prev && prev->next != entry) prev = prev->next; Both are reasonable enough that they wouldn't trigger my (pretty laissez faire) sense of "taste". My core point: checking for the end of the list should be non-negotiable. The `for` is just extra icing: it creates a scope for `prev`; you can tell at a glance that it's traversing a list. The update is closer to the termination check. But yes, this bit is negotiable.