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

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

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

Post by answerhappygod »

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) {
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply