I have a question in android studio, I can't understand how the enhanced for loop works here, and how to change it to a
Posted: Wed Apr 27, 2022 3:13 pm
I have a question in android studio, I can't understand how the
enhanced for loop works here, and how to change it to a normal
one:
int[][] winPositions = {{0, 1, 2}, {3, 4, 5}, {6, 7, 8},
{0,
3, 6}, {1, 4, 7}, {2, 5, 8},
{0,
4, 8}, {2, 4, 6}};
int[] gameState = {2, 2, 2, 2, 2, 2, 2, 2, 2};
for (int[] winPosition : winPositions) {
if
(gameState[winPosition[0]] == gameState[winPosition[1]]
&&
gameState[winPosition[1]]
== gameState[winPosition[2]] &&
gameState[winPosition[0]]
!= 2) {
enhanced for loop works here, and how to change it to a normal
one:
int[][] winPositions = {{0, 1, 2}, {3, 4, 5}, {6, 7, 8},
{0,
3, 6}, {1, 4, 7}, {2, 5, 8},
{0,
4, 8}, {2, 4, 6}};
int[] gameState = {2, 2, 2, 2, 2, 2, 2, 2, 2};
for (int[] winPosition : winPositions) {
if
(gameState[winPosition[0]] == gameState[winPosition[1]]
&&
gameState[winPosition[1]]
== gameState[winPosition[2]] &&
gameState[winPosition[0]]
!= 2) {