@Salem: Ok I tried it with out the braces and it does work, that was pretty cool since I thought it would only follow statements within braces but now I know that it does follow for the next statement.
@PehJota: That was very good example and also helped me understand better the loops!
This "concept" actually helped me understand a bit whats going on "pseudocode-wise", from what I understood of the loop:
-X starts at 0 and will loop until x < 8 increasing by 1 each loop.
-Each loop of x contains a loop of Y which starts at 0 and will loop until y < 8 increasing by 1 each loop while maintaining x in current loop.
-Then when the statements within for loop x are complete (the whole loop of y 1-8) it will continue to the next digit, which will cause y to loop again and so on.
which is why it ends like (0 1) (0 2) etc.
Ok that is one thing I didn't get (correct me if I'm wrong).
That answered my second question.
The first one was why is the two seperate for loops, i guess as PehJota says nesting. For example I tried writing:
1.
Code:
#include <iostream>
using namespace std;
int main()
{
int x;
int y;
int array[8][8];
cout<<"Array Indices:\n";
for ( x = 0; x < 8;x++ ){
for ( y = 0; y < 8; y++ )
return array[x][y] = x * y;//I have even tried with out return and simply like
//array[x][y] = x * y;
cout<<"["<<x<<"]["<<y<<"]="<< array[x][y] <<" ";
cout<<"\n";
}
and 2.
Code:
#include <iostream>
using namespace std;
int main()
{
int x;
int y;
int array[8][8];
array[x][y] = x * y;
cout<<"Array Indices:\n";
for ( x = 0; x < 8;x++ ) {
for ( y = 0; y < 8; y++ )
cout<<"["<<x<<"]["<<y<<"]="<< array[x][y] <<" ";
cout<<"\n";
}
cin.get();
}
This last one makes the program crash which made me laugh :P, but the first question mainly was why do we have to put twice the for x loop, for y loop ? (first right after setting the variables and the array and the after the cout)?
Thanks alot for the previous answers and to the future ones !