The AND (
&&) operator returns true if both of its arguments are true. Otherwise it returns false.
The OR (
||) operator returns true if either of its arguments are true, otherwise false.
You want the loop to continue until either of the following conditions occurs:
winCounter >= 4 --- if they get 4 (or more) right, the game ends
guessCounter >= 10 --- if they guessed ten (or more) times, the game ends
Or, to put it another way, you want the loop to continue looping while both of these conditions remain true:
winCounter < 4
guessCounter < 10
We'll go with the latter since it's a simpler loop condition.
If either of these conditions is false, you want the loop to stop; you want the loop to continue only while both the conditions are true.
We can use the AND (
&&) operator to tell us when either of the conditions stops being true -- because the
&& will only return true if both of its arguments are true.
So, if we AND together
winCounter < 4 and
guessCounter < 10 then when either stops being true the
&& will stop being true and that means we should exit the loop.
while ( (winCounter < 4) && (guessCounter < 10) )