ListForeachInRange
- Macro
- October 8, 2025
Table of Contents
ListForeachInRange
ListForeachInRange
Description
Iterate over each element var of the given list l in the index range [start, end). The variable var is declared and defined by this macro. This macro performs forward traversal, starting at index start (inclusive) and continuing until index end (exclusive), assuming zero-based indexing. Since linked lists are not indexable, the traversal walks node-by-node and skips nodes before start, then continues while tracking the current index.
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. |
start | in | Starting index (inclusive). |
end | in | Ending index (exclusive). |
Usage example (Cross-references)
- In
ListInt.c:304
:
if (start < end) {
int sum = 0;
ListForeachInRange(list, item, start, end) {
sum += item;
}