ListForeach

Table of Contents

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

NameDirectionDescription
linList to iterate over.
varoutName 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)

    if (list->length > 0) {
    int sum = 0;
    ListForeach(list, item) {
    sum += item;
    }
    typedef List(int) LI;
    LI li = ListInit();
    ListForeach(&li, i) {
    (void)i;
    }

Share :

Related Posts

VecForeachPtrIdx

VecForeachPtrIdx Description Iterate over each element var of given vector v at each index idx into the vector. The variables var and idx declared and defined by this macro. idx will start from 0 and will go till v->length - 1

Read More

VecForeachInRangeIdx

VecForeachInRangeIdx Description Iterate over elements in a specific range of the given vector v at each index idx. The variables var and idx are declared and defined by this macro. idx will start from start and will go till end - 1

Read More

VecForeachReverse

VecForeachReverse Description Iterate over each element var of the given vector v in reverse order. This is a convenience macro that iterates backward using an internally managed index. The variable var is declared and defined by this macro.

Read More