weird for loop


Could someone explain to me how this for loop work ?

i just don't understand the 2 extra conditions:

beg = authors.lower_bound(search_item),
end = authors.upper_bound(search_item);



1
2
3
4
5
6
7
8
9
  


for (auto beg = authors.lower_bound(search_item),
 end = authors.upper_bound(search_item); beg != end; ++beg)
 cout << beg->second << endl; 


Last edited on
Those are not conditions; they are just assignments. The condition is just the beg != end bit. A for loop requires a single statement for the initial part, so a comma was used to combine the two variable declarations and assignments into one statement.

If you are confused about the methods used to generate the values, I would look them up on a reference site and see if that helps, then ask if you have questions about what you find.
Topic archived. No new replies allowed.