Page MenuHomePhabricator

Does C++ have a for loop similiar to that of Pythons foreach loop?
Closed, ResolvedPublic

Asked by nsgroggett on Jun 8 2017, 7:17 PM.
Subscribers
Tokens
"Like" token, awarded by jcmcdonald.

Details

The foreach loop in Python is an incredibly useful function in python and it would be useful to have that in C++.

Answer Summary

In fact, C++ does have foreach loops, Though it is slightly different from what Pythons does. In addition since C++ 11 for loops have added extra functionality so that they can behave like Python's foreach. The following are links to both examples and descriptions of the new functionality of for in c++.

ranged based for
http://en.cppreference.com/w/cpp/language/range-for

for_each
http://en.cppreference.com/w/cpp/algorithm/for_each

New Answer

Answer

This question has been marked as closed, but you can still leave a new answer.