Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Last Element in ForEach

Tags:

c++

foreach

Does C++ have a pre-built method to identify which element you are on in your foreach loop, or if there is a way to identify if you are on your last element? Or do I have to do it manually with a counter?

like image 279
Jon Avatar asked Mar 09 '26 13:03

Jon


1 Answers

No, there is no such built-in way. Nor could there be for iterators in general, because iterators aren't required to know that they are "almost" at the end.

like image 126
John Zwinck Avatar answered Mar 12 '26 03:03

John Zwinck



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!