Horje
ranged based for loop c++ Code Example
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;
}
ranged based for loop c++
#include <vector>
#include <iostream>

std::vector<int> testingVector{1,2,3,4,5};
/* firstly you define the type in this case it is int then you pass it as
 reference with "&" then you choose your "name" for element in this case
 it is element after the : you type in name of the vector variable
 you use the element as a varibale which will loop around every element in
 the vector
 */
for (int& element : testingVector)
{
	element++;
}
OUTPUT: 2 3 4 5 6
//equivalent in normal for loop would be this
for(int i{}; i < testingVector.size(); i++)
{
  testingVector[i]++;
}




Cpp

Related
Explicit conversion casting Code Example Explicit conversion casting Code Example
visual studio getline not working Code Example visual studio getline not working Code Example
take single digit integer input in c++ Code Example take single digit integer input in c++ Code Example
return multiple values c++ Code Example return multiple values c++ Code Example
arduino funktion Code Example arduino funktion Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
9