J
J
Junior0072016-09-21 02:50:30
C++ / C#
Junior007, 2016-09-21 02:50:30

What does such an expression mean?

I came across this entry:

int main()
{
  std::list<int> x = {1, 2, 2, 3, 3, 2, 1, 1, 2};
 
  std::cout << "contents before:";
  for (auto val : x)
    std::cout << ' ' << val;
  std::cout << '\n';

}

Can't figure out the meaning:
for (auto val : x)

And shouldn't for have such a pattern?
for (; ;)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Armenian Radio, 2016-09-21
@Junior007

Discover C++11. This is a new language standard that has improved syntax.
for (auto val : x) is a loop through the collection x, each element of the collection will be copied to the x variable.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question