MultiD Array[][]

This is a discussion on MultiD Array[][] within the C++ Programming forums, part of the General Programming Boards category; Hello! Can i use a for() loop this way or should i use two for() loop? It compiles, executes but ...

1. MultiD Array[][]

Hello!

Can i use a for() loop this way or should i use two for() loop?
It compiles, executes but nothing gets printed out.

Code:
#include <iostream>
using namespace std;

int main(){

char board[2][33];
for(int i = 0, j = 0; board[i][j] < '\n'; i++,j++){

char board[2][33] ={{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0}};

if(i<33) cout << board[i][j];

else     cout << endl;
}

//system("pause");
return 0;
}

2. And what do you expect? There's very little here that makes sense. E.g

Code:
board[i][j] < '\n'
Why do you think comparing uninitialized values against 13 (or 10) would be relevant to the loop?

Yes, you'll need two nested loops. One that goes from 0 to 2 and the other from 0 to 33 (not including 2 and 33)

3. Code:
board[i][j] < '\n'
I saw that in somebody's code and though surprised, i assumed it was right.

Thanks for clearing things up.

4. you also have 2 board arrays - 1 not initialized outside the loop
and second you initialize on each iteration inside the loop

5. Thanks Vart!

I also made the mistake by thinking that the first value was the Width. Its the other way around.

char board [HEIGHT][WIDTH];

6. first index should be j - second i, you have it mixed up