In my previous articles about C++11 standard I talked about automatic type detection , decltype keyword and uniform initializer list introduced in C++11. Lets see the Range-based for loop today:
Earlier, the for loop which we use to traverse a list has unnecessary counter increment and check for the last element in the list. For example:If I want to print all the elements in an array, then the code will be

    // C++03 code
    int arr[10] = {0,1,2,3,4,5,6,7,8,9};
    for(int cnt=0; cnt < 10; cnt++)
        cout << arr[cnt] << endl;

Languages like java and C# already had for each loop which is easier to use in such cases. the java code will be

    // Java Code
    for(int x : arr)
        System.out.println(x); // similar to cout in C++

C++11 introduces range-based for loop which is similar to for-each loop of other languages. The above code in C++11 will be

    // C++11 Code
    int arr[10] = {0,1,2,3,4,5,6,7,8,9};
    for (int &x : arr)
        cout << x << endl;

Lets look at a more complex problem:

    // Code before C++11
    map another_class_map;
    for (map<myclass, vector>::const_iterator it = another_class_map.begin();
        it != another_class_map.end(); ++it)
    {
        ....
    }
    // C++11 Code
    map<myclass, vector> another_class_map;
    for (auto x : another_class_map)
    {
        ....
    }

See how convenient 🙂
Previous: Uniform Initializer List in C++11
Next: Separate Null Pointer in C++11

2 Responses

  1. Отдельно хочу отметить мелочи, про которые многие забывают: замена защелки двери спб, ремонт ригелей замка спб, ремонт замка без снятия двери спб, ремонт замка на металлической двери на дому спб. Обычно вспоминаешь об этом, когда уже дверь не закрывается или наоборот — не открывается. Нормальный вызов мастера по замкам спб цена сейчас, конечно, не копейки, но это всё равно дешевле, чем потом менять полотно или ломать дверь. Я для себя решил, что проще следить за замками и вовремя консультироваться со специалистами по выбору механизма на том же https://avers-zamki.ru/.

  2. Приложение работает быстро и стабильно в использовании. 7к казино скачать лучше чем браузерная версия даже.

  3. DatabaseLeak – The Ultimate Password Exposure Database
    Don’t guess passwords — reveal them. DatabaseLeak lets you explore a world password list, uncover leaked credentials, and track every password found across the dark web.
    Access 33B+ compromised accounts and 50M new breaches daily, including a list of all passwords, a suggested passwords list, and the most commonly used passwords that hackers exploit.
    Run a free scan, detect compromised passwords, expose hashed passwords, and see used passwords from countless sites — all in seconds.
    Unlock full access for only $2 — gain real intelligence, not rumors.
    Find Out: Powerful password list

    |

  4. Informationbreach – Know If Your Data Is Already Leaked
    Massive data breaches happen every day. Check if your email, credit info, or personal data appears in leaked or hacked databases.
    Scan 33B+ leaked passwords and 50M new breach records daily to detect exposure instantly.
    Get breach alerts, see if your accounts are in credit card leaks, email breaches, or hacked dumps — all in one click.
    Protect yourself from identity theft for just $2 — your breach awareness shield starts now.
    Check Your Exposure Now: [url=https://informationbreach.net] Data breach of personal information[/url]

    |

  5. Antipublic – Stop Data Exposure Before It Destroys You
    Your personal information data breach may already be live on the dark web. Antipublic reveals hidden data exposure risks and protects you from costly security breaches.
    Access 33B+ leaked passwords and track 50M new records daily in real time. Scan any user, domain, or email instantly and prevent massive loss before it happens.
    Only $2 unlocks full protection.
    Check now: Data exposure risk

    |

  6. Informationbreach – Your Email May Already Be Exposed
    Your inbox isn’t safe anymore. Hackers mail, stolen logins, and email vulnerability are spreading fast — and your email address on the dark web could be the next target.
    Informationbreach scans 33B+ breached passwords and 50M new records daily to reveal if your account has been compromised. Instantly check email in dark web, detect hack email account attempts, and verify credentials security before damage happens.
    Run a real-time exposure check, see if someone has hacked into your email, and secure your identity with accurate results — not guesses.
    Full access is just $2 — unlock everything, stay protected, and take control before hackers do.
    Scan Email Now: Email hack app

    |

  7. Just found BitsIntelligence – an amazing free live world intelligence dashboard.

    Check it out: https://biitel.com/

    It gives you monitor everything in one place:
    – Automatic breaking news
    – Live market data
    – Air traffic tracker
    – Ship tracker using AIS
    – Earthquake notifications
    – Crude oil, civil unrest & power outages monitoring

    Completely free – no signup needed.

    https://biitel.com/

    ===== SIGNATURE VARIATIONS =====

    BiiTel | Free Live World News Dashboard | https://bitsintelligence.ai/
    Source: https://bitsintelligence.ai/ – No Cost AI-Powered Global Intelligence Platform
    Visit BiiTel – A Top Free OSINT Platform: https://bitsintelligence.ai/

  8. Data-Leaks – Stop Guessing. Start Knowing!
    Your data might already be out there — find out now with Data-Leaks, the fastest and smartest global leak scanner.
    Search 33B+ stolen passwords and 50M fresh leaks daily in just one simple click.
    Run a Data-Leaks dark web scan, check if your account was hacked, and get instant, accurate results.
    Only $2 for total access — your Data-Leaks identity theft protection tool is just one click away!
    Reveal the Truth: Data dark web

    |

Leave a Reply

Your email address will not be published. Required fields are marked *