Explain solidity>nested loops

Nested Loops

Now we need to detect when a player has won by getting three in a row.

Board Layout:

Our board is stored as a flat array with 9 positions:

[0, 1, 2, 3, 4, 5, 6, 7, 8]

This represents a 3x3 grid:

Row 0: positions 0, 1, 2
Row 1: positions 3, 4, 5
Row 2: positions 6, 7, 8



The && Operator:

&& means "and". All conditions must be true.

a == b && b == c means "a equals b AND b equals c"



Checking Rows:

For row i, the three positions are: i*3, i*3+1, i*3+2

Row 0: 0*3 = 0, 0*3+1 = 1, 0*3+2 = 2
Row 1: 1*3 = 3, 1*3+1 = 4, 1*3+2 = 5
Row 2: 2*3 = 6, 2*3+1 = 7, 2*3+2 = 8



Create a checkWin function that loops through the 3 rows and checks if all three cells match and aren't Empty.

Create checkWin function for rows
0%
Requirements:
Declares function checkWin
Function is private view
Returns bool
Has for loop checking 3 rows
Checks cell is not Empty
Uses && operator
Checks all three cells in row match
Returns true if match found
Returns false at end