Hint $\ $ For $\rm\:b=1\:$ it is $\rm\: a^2 = 0\:\Rightarrow\: a= 0,\:$ which is not true in every ring, e.g. $\rm\ a = n\:$ in $\rm\: \Bbb Z/n^2.$
This is essentially the only obstruction, i.e. the statement holds true iff the ring is reduced, i.e. iff the ring has no nonzero nilpotent elements, i.e. $\rm\: x^n = 0\:\Rightarrow\: x = 0.\:$
Theorem $\ $ The following are equivalent in any ring.
$\rm(1)\quad xyx = 0\ \Rightarrow\ xy=0\ \ or\ \ yx=0$
$\rm(2)\quad x^2 = 0\ \Rightarrow\ x=0$
$\rm(3)\quad x^n = 0\ \Rightarrow\ x=0$
Proof $\ \ \ \ (1\Rightarrow 2)\ \ \ $ Put $\rm\:y = 1.\:$
$(2\Rightarrow 3)\ \ \, $ The least $\rm\:n\:$ such that $\rm\:x^n = 0\:$ is $\rm\:n = 1\:$ since any larger value can be reduced, viz.
$$\begin{eqnarray}\rm x^{2k} = 0\ &\Rightarrow&\rm\ (x^k)^2\! &=& 0\ &\Rightarrow&\rm\ x^k &=& 0\\
\rm x^{2k+1}\!=0\ &\Rightarrow&\rm\ (x^{k+1})^2\! &=& 0\ &\Rightarrow&\rm\ x^{k+1} &=& 0\end{eqnarray}$$
$\rm(3\Rightarrow 1)\ \ \ $ If $\rm\:xyx = 0\:$ then $\rm\: (xy)^2 = (xyx)y = 0,\:$ hence $\rm\: xy = 0\:$ by $(3)$.
Remark $\ $ The absence of nilpotent elements facilitates simpler structure theory, e.g. Weierstrass (1884) and Dedekind (1885) showed that every finite dimensional commutative extension ring of $\mathbb R$ without nilpotents is isomorphic as a ring to a direct sum of copies of $\rm\:\mathbb R\:$ and $\rm\:\mathbb C\:.\:$Wedderburn and Artin proved a generalization that every finite-dimensional associative algebra without nilpotent elements over a field $\rm\:F\:$ is a finite direct sum of fields.
Such structure-theoretic results greatly simplify classifying such rings when they arise in the wild. For example, I applied a special case of these results here to prove that a finite ring is a field if its units $\cup\ \{0\}$ comprise a field of characteristic $\ne 2\:.\:$ For another example, a sci.math reader once proposed an extension of the real numbers with multiple "signs". This turns out to be a very simple case of the above results. See my answer in Is there a third dimension of numbers? for much further discussion, including references.