ListForeach
- Macro
- October 8, 2025
Table of Contents
ListForeach
ListForeach
Description
Iterate over each element var of the given list l. The variable var is declared and defined by this macro. Iteration happens in forward order, starting from the head of the list and continuing through the next pointers until the end is reached. The variable var will contain a copy of the value pointed to by each list node.
Parameters
Name | Direction | Description |
---|---|---|
l | in | List to iterate over. |
var | out | Name of the variable to be used which will contain the value of the current element during iteration. The type of var will be the data type of the list elements (obtained via LIST_DATA_TYPE(l)). |
Usage example (Cross-references)
typedef List(int) LI;
LI li = ListInit();
ListForeach(&li, i) {
(void)i;
}
- In
ListInt.c:213
:
if (list->length > 0) {
int sum = 0;
ListForeach(list, item) {
sum += item;
}