‘colon’ and ‘auto’ in for loop c++? need some help understanding the syntax

This is a range based for loop, it has the same basic behavior of:

for(auto it = deviceList.begin(); it != deviceList.end(); ++it)
{
   const auto& ioDev = *it;
}

The range based for loop has quickly become one of my favorite constructs, it’s terse and when you need to iterate an entire range, works as well (and as efficiently) as possible.

If you need the other constructs of a typical for loop (say to exit early in some case), then range-based for isn’t for that use case.

Leave a Comment