ListForeachReverse

Table of Contents

ListForeachReverse

Description

Iterate over each element var of the given list l in reverse order. The variable var is declared and defined by this macro. Iteration happens in reverse, starting from the tail of the list and continuing through the prev pointers until the head 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;
    ListForeachReverse(list, item) {
    sum += item;
    }

Share :

Related Posts

VecForeachPtrInRangeIdx

VecForeachPtrInRangeIdx Description Iterate over elements in a specific range of the given vector v at each index idx (as pointers). 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

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

VecForeachPtrInRange

VecForeachPtrInRange Description Iterate over elements in a specific range of the given vector v (as pointers). This is a convenience macro that iterates over a range using an internally managed index and provides a pointer to each element. The variable var is declared and defined by this macro as a pointer to the vector’s data type.

Read More