Can someone please explain further for me on this part of the code
sum += val; //I understand that it is the same as sum=val+sum and I am able to use it later in cout to represent the total sum
++val; //I dont understand this;adds one to val,and keep repeating until it reaches 10,but isn't val stored to sum and then val is increased?and how did they add up all inclusive ?
#include <iostream>
usingnamespace std;
int main()
{
int sum = 0, val = 1;
// keep executing the while as long as val is less than or equal to 10
while (val <= 10) {
sum += val;
++val;
}
cout << "Sum of 1 to 10 inclusive is " << sum << endl;
return 0;
}