ben3019201
ben3019201

Reputation: 391

Nested for loop array initialization

I want to initialize a 2-d array gameBoard and display the result on screen. Will the following nested for loops work? I'm having trouble displaying it on the screen so I can't tell if this is working correctly or not.

for (NSInteger x = 0; x <= 2; x++)
{
    for (NSInteger y = 0; y <=2; y++)
    {
        gameBoard [x][y] = 0;
        NSLog(@"%ld"), gameBoard [x][y];
    }
}

Upvotes: 0

Views: 187

Answers (1)

Carl Norum
Carl Norum

Reputation: 225252

Your NSLog line is wrong, but other than that you're ok (assuming your array is appropriately sized, that is). Change the log line to:

NSLog(@"%ld", gameBoard[x][y]);

to get some actual output. Now that I look again, I think your example won't even compile cleanly the way it is.

Upvotes: 1

Related Questions