lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 3/28/2017 1:10 AM, Javier Guerra Giraldez wrote:
> On 28 March 2017 at 07:14, Ahmed Charles <acharles@outlook.com> wrote:
>> I find this amusing because I've never written "len - 1" in a loop, I've
>> only ever written "!= len".
> 
> 
> don't you mean "< len" ?

Nope...

for (auto i = ..., e = ...; i != e; ++i) {}

That form of for loop in C++ can be used for any range/container that
follows the iterator paradigm used by the STL. This is because <
requires random access iterators, but != works with any iterator.

Granted, since C++11, I prefer...

for (auto&& item : ...) {}

Mostly because this is more restrictive.