We can reverse the process of iterating the loop by using boost::adaptors::reverse() function which is included in boost library Header.
for (auto i : boost::adaptors::reverse(x))
- 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++:
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
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- C/C++ while loop with Examples
- C/C++ For loop with Examples
- C/C++ do while loop with Examples
- for_each loop in C++
- How will you print numbers from 1 to 100 without using loop?
- Difference between while and do-while loop in C, C++, Java
- Difference between for and while loop in C, C++, Java
- Difference between for and do-while loop in C, C++, Java
- Range-based for loop in C++
- Print 1 to 100 in C++, without loop and recursion
- Detect loop in a linked list
- Print pattern using only one loop | Set 1 (Using setw)
- Print Number series without using any loop
- Different types of range-based for loop iterators in C++
- Difference between Sentinel and Counter Controlled Loop in C
- Find length of loop in a Linked List using Map
- What happens if loop till Maximum of Signed and Unsigned in C/C++?
- Print a character n times without using loop, recursion or goto in C++
- Printing triangle star pattern using a single loop
- Print a number 100 times without using loop, recursion and macro expansion in C?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.