Multiplication is a commutative operation (a*b and b*a are the same quantity). That means that we can eliminate half of the operations making the inner
J loop stop when
$j becomes lesser than
$i. You can see that explicit as the condition of the
J loop.
Other trick used to trim the search space is taking into account that for natural numbers if a >= b then a*c >= b*c, so as soon as we found a $j that makes a palindrome we can stop the J loop.
Finally whatever becomes $prod <= $best we can also stop J; or even I if $j is still at 999.