0

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];
    }
}
1
  • 1
    FWIW, this is going to log column-major. Generally you want the row loop (y) to be the outer loop. Commented Jan 27, 2012 at 1:01

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Ops I should have realized my parenthesis mistake. Yeah I was getting an error but it was compiling something crazy ha

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.