iterating through object list

Hello!

I have recently seen a Java syntax to iterate through an object list (myObjects)
If was something like:

1
2
3
4
5
6

for (object obj : myObjects){
    
     object.doSomething
}


Is there something similar in C++, or any shorter way than the classic for loop with myObjects.size() as the incrementing condition?
Thank you!



Last edited on
closed account (2LzbRXSz)
Like a range-based loop, right?

You can read about them here (you'll have to scroll down a bit)
http://www.cplusplus.com/doc/tutorial/control/

And here's a specific article all about range-based loops (I can't vouch for it because I only took a quick glance over it, but it seems pretty informative).
http://en.cppreference.com/w/cpp/language/range-for

Edit: I like your username by the way.
Last edited on
"range based loop"
exactly.

I scrolled down this very page a few hours ago but too quickly obviously, sorry for that!
Thanks for pointing this two links Cactus.

(this was the first thing that came to my mind when registering my username...
Has yours been chosen to warn newbies about C++ needles?)
closed account (2LzbRXSz)
No problem:)

(That's amazing. and Haha, nice one! I just picked it because it was easy to remember, and to my surprise, it's typically not taken ((and if it is, I just alternate to cactus3, which isn't ever taken)).)
Topic archived. No new replies allowed.