On Mon, Sep 10, 2012 at 3:44 PM, Jeff King <peff@xxxxxxxx> wrote: > On Sun, Sep 09, 2012 at 03:44:54PM +0100, David Gould wrote: >> You want something like: >> >> for (... { >> if (... { >> ... >> } >> last = &p->next; >> } >> >> or (probably clearer, but I haven't read your coding style guide, if >> there is one, and some people don't like this approach) > > Yes, that's the correct fix. Care to submit a patch? > >> for (p = children_to_clean; p; last = &p->next, p = p->next) { >> ... > > That is OK, too, but I think I prefer the first one. > I feel like bikeshedding a bit today! I tend to either prefer either the latter or something like this: while (p) { ... last = p; p = p->next; } because those approaches put all the iteration logic in the same place. The in-body traversal approach is a bit more explicit about the traversal details. And to conclude my bikeshedding for the day: Shouldn't "last" ideally be called something like "prev" instead? It's the previously visited element, not the last element in the list. -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html