Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7808867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:15:27+00:00 2026-06-02T03:15:27+00:00

The latest C++ 11 specification defines a new type of for loop called range-based

  • 0

The latest C++ 11 specification defines a new type of for loop called “range-based for loop”.
Its looks and mechanics appear to be pretty much identical to the for-each loops available in other languages.

What are the differences between the two of them, if any? If there are no differences why the new name?

Edit: To clarify, I’m not looking for implementation differences between the “range based for” of c++ and other languages’ for each or std::for_each. Instead I was wondering if there was some hidden value behind the fact that they decided to call this new c++ “feature” (or syntax, or idiom or whatever you want to call it) “range-based for loop” instead of “for each loop” as pretty much anyone else seems to be calling these things.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T03:15:29+00:00Added an answer on June 2, 2026 at 3:15 am

    Syntax:

    for ( range_declaration : range_expression) loop_statement  
    

    produces code equivalent to:

    {
        auto && __range = range_expression ; 
        auto __begin = begin_expr(__range); 
        auto __end = end_expr(__range); 
        for (;__begin != __end; ++__begin) { 
            range_declaration = *__begin; 
            loop_statement 
        } 
    } 
    

    While the std::for_each applies unary function to the specified range. So, there are two basic differences:

    • The range-based for-loop syntax is cleaner and more universal, but you can’t execute the code in loop for a specified range different than from begin() to end().
    • Range-based for-loop can be applied to containers which don’t have iterators defined, by defining begin() and end() functions.

    You cannot compare it to the “generalized for-each idiom”, because there is no standard idiom. To compare, you have to point out the concrete implementation and the difference is usually hidden in the details.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I read the latest DOM specification, which is under draft, that the new DOM
The latest Google App Engine release supports a new Task Queue API in Python.
With the latest jqModal release (+r14), I'm having an issue with the new feature
I have installed the latest version of netbeans and its working.. I have opened
I have read about partial methods in the latest C# language specification , so
When a new specification comes out (like HTML 5) it can be tempting to
My latest project is to build a billing system with multiple profile like 100+
The latest Python2.7 has a google directory within dist-packages , making it impossible to
So Hibernate Supports the latest Version of Firebird, which is really great. But... I
I am using the latest NHibernate 2.1.0Beta2. I'm trying to unit test with SQLite

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.