Welcome to forums!
I'm fairly new to programming myself, so I may be wrong, but I believe the output would actually be sum. If you wanted to see the values of i and j you could do:
#include<iostream>
usingnamespace std;
int main()
{
int i;
cout << "loop number 1..." << endl;
//here the body of the loop consists only of
//cout << i << ' ';
for (i=0; i<10; i++)
cout << i << ' ';
cout << "asdf" << endl;
cout << "loop number 2..." << endl;
//here the body of the loop consists of
//everything you place inside the brackets {,}
for (i=0; i<10; i++)
{
cout << i << ' ';
cout << "asdf" << endl;
}
cout << "hit enter to quit..." << endl;
cin.get();
return 0;
}
The simple answer to why you're not getting the desired output is that the code which you want your for loop to run, is not actually inside the for loop.
1 2 3
for (i=o ; i < 3 ; i++)
cout << "This line will run.";
cout << "But not this one.";
Without code blocks, your loop will only read the first line after the actual loop is initialized.
So to fix this, simply add opening and closing braces when you have more than one statement:
1 2 3 4 5
for (i=o ; i < 3 ; i++)
{
cout << "This line will run.";
cout << "And this one too.";
}