Does C have a “foreach” loop construct?
C doesn’t have a foreach, but macros are frequently used to emulate that: #define for_each_item(item, list) \ for(T * item = list->head; item != NULL; item = item->next) And can be used like for_each_item(i, processes) { i->wakeup(); } Iteration over an array is also possible: #define foreach(item, array) \ for(int keep = 1, \ count … Read more