Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP PHP Arrays and Control Structures PHP Loops Ping Pong

yahya alhalki
yahya alhalki
1,149 Points

why do we have to put parentheses round ($player1 < 11 && $player2 < 11) )?

//My Code


$player1 = 1;
$player2 = 2;
$round = 0;
$difference = abs($player1 - $player2) < 2;

while($difference|| ($player1 < 11 && $player2 < 11) ){

    echo "<h2>round $round<h2/>\n";


  } else{
 echo "player 1 = $player1<br />\n";
echo "player 2 = $player2<br />\n";


//why do we have to put parentheses round  ($player1 < 11 && $player2 < 11) )

You need to explain your question to get an answer. The title of your question is vague.

2 Answers

yahya alhalki
yahya alhalki
1,149 Points

what is the use of that. i tried to remove the parenthesis and they both execute the same way

Damir Paulić
Damir Paulić
6,591 Points

Well, because of the operator precedence, parentheses in this case is not needed. "&&" is executed before "||". https://www.php.net/manual/en/language.operators.precedence.php

Personally, I would still use parentheses because it could get overwhelming to think about precedence while still figuring the logical part.