# Iterated Expecation of Conditional Expectation

I'm trying to show that $$E[(Y- E[Y|X])(E[Y|X] - E[Y])] = 0.$$ My attempt is as follows: \begin{align*} & E[(Y- E[Y|X])(E[Y|X] - E[Y])] \\ &= E[YE[Y|X] - Y E[Y] - E[Y|X]^2 +E[Y|X]E[Y]]\\ &= E[YE[Y|X]] - E[Y E[Y]] - E[E[Y|X]^2] +E[E[Y|X]E[Y]]\\ &= E[E[Y|X]E[Y|X]] - E[E[Y|X] E[Y]]\\ &\qquad - E[E[Y|X]^2] +E[E[Y|X]E[Y]]\\ &= 0 \end{align*}

However, I seemed to have misused the law of iterated expectations when I set $$E[YE[Y|X]] = E[E[Y|X]E[Y|X]].$$ How can I justify this? Or is it just wrong?

Note that $E[Y\mid X]$ is $\sigma(X)$-measurable, hence $$E[Y\mid X]^2 = E[YE[Y\mid X]\mid X]$$ giving $$E \bigl[E [Y \mid X]^2\bigr] = E\bigl[ E[YE[Y\mid X]\mid X] \bigr] = E\bigl[YE[Y\mid X]\bigr].$$