Hi everyone
the book that i'm learning from says that this for loop has no body,
first of all, I don't even no what that means, this for loop looks quit
the usual.
besides the above issue another bazaar thing is that all other for loops
do not have a semi-colon after the brackets, this one does and if
i remove it i get a funny output, if i place the semi-colon there i get
SUM IS 55 as an output and I dont understand why.
help please.
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int i, sum = 0;
//sum the numbers from 1 to 10
for(i=1; i <= 10; sum += i++);
cout << "sum is " << sum;
cin.get();
cin.get();
return 0;
}
the book that i'm learning from says that this for loop has no body,
first of all, I don't even no what that means, this for loop looks quit
the usual.
besides the above issue another bazaar thing is that all other for loops
do not have a semi-colon after the brackets, this one does and if
i remove it i get a funny output, if i place the semi-colon there i get
SUM IS 55 as an output and I dont understand why.
help please.
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int i, sum = 0;
//sum the numbers from 1 to 10
for(i=1; i <= 10; sum += i++);
cout << "sum is " << sum;
cin.get();
cin.get();
return 0;
}
Comment