Reversed Range-based for loop in C++ with Examples Last Updated : 08 Jul, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report Range-based for loops is an upgraded version of for loops. It is quite similar to for loops which is use in Python. Range-based for loop in C++ is added since C++ 11. We can reverse the process of iterating the loop by using boost::adaptors::reverse() function which is included in boost library Header. Header File: #include <boost/range/adaptor/reversed.hpp> Syntax: for (auto i : boost::adaptors::reverse(x)) Parameters: range_declaration: a declaration used to iterate over the elements in a container. Often uses the auto specifier for automatic type deduction. range_expression: An expression that represents a suitable sequence or a braced-init-list. loop_statement: An statement, typically a compound statement, which is the body of the loop. Below is the program to illustrate reverse range based loop in C++: CPP14 // C++ program for reverse // range-based for loop #include <bits/stdc++.h> // For reversing range based loop #include <boost/range/adaptor/reversed.hpp> using namespace std; // Driver Code int main() { string s = "geeksforgeeks"; int y[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; vector<int> v1{ 1, 2, 3, 4, 5, 6, 7, 8 }; // Reverse range-based for loop // to reverse string for (auto x : boost::adaptors::reverse(s)) cout << x << " "; cout << endl; // Reverse range-based for loop // to reverse array for (auto x : boost::adaptors::reverse(y)) cout << x << " "; cout << endl; // Reverse range-based for loop // to reverse vector for (auto x : boost::adaptors::reverse(v1)) cout << x << " "; cout << endl; return 0; } Output: s k e e g r o f s k e e g 8 7 6 5 4 3 2 1 8 7 6 5 4 3 2 1 Comment More infoAdvertise with us Next Article Nested Loops in C++ with Examples K kothariji Follow Improve Article Tags : C++ loop Practice Tags : CPP Similar Reads Nested Loops in C++ with Examples Nested loop means a loop statement inside another loop statement. That is why nested loops are also called as "loop inside loop". Syntax for Nested For loop: for ( initialization; condition; increment ) { for ( initialization; condition; increment ) { // statement of inside loop } // statement of ou 3 min read Range-Based for Loop in C++ In C++, the range-based for loop introduced in C++ 11 is a version of for loop that is able to iterate over a range. This range can be anything that is iteratable, such as arrays, strings and STL containers. It provides a more readable and concise syntax compared to traditional for loops.Let's take 3 min read std::search_n with example in C++ Prerequisite: std::search std::search_n is an STL algorithm defined inside the header file , which is used to search whether a given element satisfies a predicate (equality if no such predicate is defined ) a given no. of times consecutively with the container elements. It searches the range [first, 4 min read Vector of Vectors in C++ STL with Examples In C++, a vector of Vectors is a two-dimensional vector with a variable number of rows, where each row is a vector. Each index of a vector stores a vector that can be traversed and accessed using iterators. It is similar to an Array of Vectors but with dynamic properties. Syntax:C++vector<vector 4 min read forward_list::cend() in C++ STL with Example forward_list::cend() is a function in C++ STL which returns a constant iterator pointing to the past-the-last element of the forward_list. The iterator returned by the function does not point to any element in the container, but to the position followed by the last element of the forward list contai 2 min read Array of list in C++ with Examples What is an array? An array in any programming language is a data structure that is used to store elements or data items of similar data types at contiguous memory locations and elements can be accessed randomly using indices of an array. Arrays are efficient when we want to store a large number of e 5 min read Like