Reply to post: why not simply have a 'foreach'....

What's all the C Plus Fuss? Bjarne Stroustrup warns of dangerous future plans for his C++

Anonymous Coward
Anonymous Coward

why not simply have a 'foreach'....

"why not simply have a 'foreach' ?

foreach (x in v) x++;"

Because that would require reserving another keyword, unnecessarily breaking lots of existing code , when 'for' is already reserved and easy to understand, the only new bit of syntax is the reuse of the ':' the rest is all normal C++

You could just as easily write

std::vector<int> v

for(int i : v) ....

Backwards compatibility.... for when your language is not just a fashionable toy

POST COMMENT House rules

Not a member of The Register? Create a new account here.

  • Enter your comment

  • Add an icon

Anonymous cowards cannot choose their icon