Hi everyone
Not a broken code thing, more a request for a lesson in theory (I got my problem fixed)
In my match 3 experimenting I had a bit of broken code that looked like this
//if the nextPiece matches the startPiece
if(nextPiece.matchValue == startPiece.matchValue)
{
//safety check that the piece isn't already in the list
if (!matches.Contains(nextPiece))
{
//add the next game piece to our list of matches
matches.Add(nextPiece);
}
else //the next piece isn't a match
{
//break out of the loop
break;
}
}
The problem was resolved by replacing the nested ifs with this line!
if (nextPiece.matchValue == startPiece.matchValue && !matches.Contains(nextPiece))
My issue is, aren’t these just the same?! I always thought they were both performing the same function, that both conditions have to be met. But my fix tells me otherwise.
Can some experience code guru explain to me the difference between a nested if and using &&? I need to get my head around this to make sure it doesn’t happen again