-
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;
}
-
And what do you expect? There's very little here that makes sense. E.g
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)
-
I saw that in somebody's code and though surprised, i assumed it was right.
Thanks for clearing things up.
-
you also have 2 board arrays - 1 not initialized outside the loop
and second you initialize on each iteration inside the loop
-
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];
-
first index should be j - second i, you have it mixed up