Answers for "for loop range based c++"

C++
7

range based for loop c++

array<int, 5> values = {1, 2, 3, 4, 10};
// the type declaration below must be consistent with the array type
for (int x : values){ //we use a colon instead of in
cout << x << endl;
}
Posted by: Guest on May-25-2020
-1

iterate over a range in c++

for (int i=0; i<5; ++i) {
  cout << i << " ";
}
// output is 0 1 2 3 4; note 5 is excluded since < is used and not <=
Posted by: Guest on September-13-2020

Browse Popular Code Answers by Language