difficulty in -nested for loops-

hello, can someone help me, i have a test due next week and i have a bit of difficulty understanding nested for loops.

Write a C++ code to produce the pattern below by using nested for loop.

0 # # # #
# 0 # # #
# # 0 # #
# # # 0 #
# # # # 0

can anyone explain to me how this work? like what makes the 0 change places?
1
2
3
4
5
6
7
8
9
int i, j;
for(i = 0; i < 5; i++)
{
    for(j = 0; j < 5; j++)
    {
        if(i == j) cout << "0 "; else cout << "# ";
    }
    cout << endl;
}


The trick is this one :
if(i == j)

Topic archived. No new replies allowed.