MSDN : a for loop executes a statement or statement block several times until the specified expression evaluates to false.
The main thing is to understand what the operator or block of operators performs . The nested for in your example is an operator that contains a block of statements because of the { } pair.
So, if you wrote above, as soon as there is one statement for each nested operation, you will write:
for (int y = 0; y < GameBoard.GameBoardHeight; y++) for (int x = 0; x < GameBoard.GameBoardWidth; x++) if (GetSquare(x, y) == "Empty") RandomPiece(x, y);
or as a block statement for each nested operation:
for (int y = 0; y < GameBoard.GameBoardHeight; y++) { for (int x = 0; x < GameBoard.GameBoardWidth; x++) { if (GetSquare(x, y) == "Empty") { RandomPiece(x, y); } } }
source share