<?xml-stylesheet type="text/xsl" href="https://community.element14.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>modern C++ for loop, but you still want an index</title><link>/technologies/code_exchange/b/blog/posts/modern-c-for-loop-but-you-still-want-an-index</link><description>C++ has a range loop. A for loop that will run over all elements in the range you give it:
std::vector&amp;lt;int&amp;gt; v = {0, 1, 2, 3, 4, 5};
// ...

 for (auto i : v)
 std::cout &amp;lt;&amp;lt; i &amp;lt;&amp;lt; &amp;#39; &amp;#39;;
 std::cout &amp;lt;&amp;lt; &amp;#39;\n&amp;amp;#...</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: modern C++ for loop, but you still want an index</title><link>https://community.element14.com/technologies/code_exchange/b/blog/posts/modern-c-for-loop-but-you-still-want-an-index</link><pubDate>Fri, 07 Nov 2025 02:58:06 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:9183c041-eb49-4a15-8c01-3757463c53a9</guid><dc:creator>Stuart_S</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;Is the &amp;#39;auto&amp;#39; keyword valid in basic C, I might give it a shot on the old DevCPP&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=29326&amp;AppID=74&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: modern C++ for loop, but you still want an index</title><link>https://community.element14.com/technologies/code_exchange/b/blog/posts/modern-c-for-loop-but-you-still-want-an-index</link><pubDate>Thu, 06 Nov 2025 20:24:13 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:9183c041-eb49-4a15-8c01-3757463c53a9</guid><dc:creator>DAB</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;Nice post Jan.&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=29326&amp;AppID=74&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: modern C++ for loop, but you still want an index</title><link>https://community.element14.com/technologies/code_exchange/b/blog/posts/modern-c-for-loop-but-you-still-want-an-index</link><pubDate>Wed, 05 Nov 2025 21:41:18 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:9183c041-eb49-4a15-8c01-3757463c53a9</guid><dc:creator>Jan Cumps</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;The example in this blog is trivial. But range for loops&amp;nbsp;are intuitive, even for&amp;nbsp;more complex containers.&lt;/p&gt;
&lt;p&gt;[embed:dc8ab71f-3b98-42d9-b0f6-e21e02a0f8e2:0722ee5a-0fa5-42b7-8bfc-bf47036fd57c:type=csharp&amp;text=%20%20%20%20for%20%28auto%20%26h%3A%20handlers%29%20%7B%0A%20%20%20%20%20%20%20%20pio_irq_manager_t%3A%3Aregister_handler%28h.pio%2C%20h.sm%2C%20%26h%2C%20true%29%3B%0A%20%20%20%20%7D]&lt;/p&gt;
&lt;p&gt;The container in the example above is an STL array (called handlers) of Raspberry Pico stepper motor objects.&amp;nbsp;The loop visits&amp;nbsp;each of the objects.&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=29326&amp;AppID=74&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item></channel></rss>