Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>What are the differences between the two of them, if any? <strong>If there are no differences why the new name?</strong></p> </blockquote> <p>In fact, it is the old name : <code>for</code>. </p> <p>If you meant why C++ doesn't add a new name, such as <code>foreach</code>, to the language like other languages have done, then you tell us why add a <em>new</em> name when old name works fine?</p> <hr> <p>From your comment:</p> <blockquote> <p>But to my knowledge all others call this type of syntax a "for-each loop". The new name for the concept had me asking if there is indeed more differences than I can see.</p> </blockquote> <p>Alright. It is about the terminologies : <em>for-each-loop</em> vs. <em>range-based-for-loop</em>.</p> <p>I think it is because C++ range-based-for-loop basically iterates <em>all elements in the range</em> defined by <em>std::begin(c)</em> and <em>std::end(c)</em>. In other words, the name <em>range-based-for-loop</em> emphasizes the philosophy of <code>begin</code> and <code>end</code> iterators which define the <em>range</em>. </p> <p>To explain that further, range-based-for-loop would work only for those collection for which <code>begin()</code> and <code>end()</code> are defined:</p> <pre><code>std::vector&lt;int&gt; v; int a[100]; int *p = new int[100]; for(int i : v) {} // works : begin(v) and end(v) are defined for(int i : a) {} // works : begin(a) and end(a) are defined for(int i : p) {} // does not work : begin(p) and end(p) are not defined </code></pre> <p>Hope that helps.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload