Iterating Backwards in C
Home Iterating Backwards in C David Priver, October 24th, 2026 This is shorter than some of my other posts, but I keep seeing people doing this wrong. It's even worse now in the LLM era. Let's say you have a buffer and a counter and you need to iterate it backwards for some reason: _Bool find_last(size_t count, int *haystack, int needle, size_t *where); Almost everyone can do the forward version on autopilot: for(size_t i = 0; i < count; i++){ if(haystack[i] == needle){ *where = i; return 1;
Read full article →