converting for loop to while loop

hi, can anyone help me? i can't seem to convert my loop.

this is my for loop
int i = 1;
const char square = '&';

for (int i = 1; i <= n; i++)
{
cout << square;
for (int i = 1; i < n; i++)
cout << '\t' << square;
cout << endl;
}

this is my while loop
int i = 1;
const char square = '&';

while (i <= n)
{
cout << square;
while (i < n)
{
cout << '\t' << square;
i++;
}
i++;
}

is there a problem with the conversion?
Yes you are incrementing two times i ... why you just don't use two differente variables names like i and j it's simplier
but even if i change it to 2 different variables, i don't get the same result as my for loop
FOR:
1
2
3
4
5
6
7
const char square = '&';

for(int i = 0; i < n; ++i){
    cout << square;
    for(int j = 0; j < n - 1; j++) {cout << '\t' << square;}
    cout << endl;
}


WHILE:
1
2
3
4
5
6
7
8
9
10
11
int i = 0, j = 0;
const char square = '&';

while (i < n){
    cout << square;
    while (j < n - 1){
        cout << '\t' << square;
        j++;
    }
    i++;
}
Topic archived. No new replies allowed.