Basic Property of Conditional Expectation Let $(\Omega, F, P)$ probability space. Let $B \subseteq F$. Let $X,Y \in  \mathcal{L}^1(P)$
I know, that:
$\mathbb{E}[X] = \mathbb{E}[\mathbb{E}[X|B]]$
But, is this legal?
$\mathbb{E}[X] = \mathbb{E}\left[\mathbb{E}[X|B]]= \mathbb{E}[X \mathbb{E}[0|B]\right]$
If not, how can I take the $X$ out of the second integral?
 A: If $B$ is a $\sigma$-algebra and $B \subseteq F$

$$\mathbb{E}\left[\mathbb{E}[X|B]]= \mathbb{E}[X \mathbb{E}[0|B]\right]$$

is wrong because
$$RHS = \mathbb{E}[X \mathbb{E}[0|B]] = E[X(0)] = 0$$
$$LHS = \mathbb{E}\left[\mathbb{E}[X|B]] = E[X\right]$$
For any $E[X]\ne0$, we have our contradiction.
Now if $X\in mB$, then
$$\mathbb{E}\left[\mathbb{E}[X|B]]= \mathbb{E}[X \mathbb{E}[1|B]\right]$$
As for 'taking $X$ out of the second integral', there might not exactly be a second integral there: $\mathbb{E}[X|B]$ is merely notation for any $B$-measurable and integrable random variable $Z$, in the same probability space as X, such that
$$\int_G Z dP = \int_G X dP \ \forall \ G \ \in \ B$$
Thus, $$\mathbb{E}\left[\mathbb{E}[X|B]\right] = \mathbb{E}[Z] = \int_{\Omega} Z dP$$
I see only one integral there.

If $B$ is an event, i.e. $B \in F$, and assuming $P(B) > 0$, then we have
$\mathbb{E}[X|B] := \frac{\mathbb{E}[X1_B]}{P(B)}$, which is a number.
Thus
$$\mathbb{E}[\mathbb{E}[X|B]]= \mathbb{E}[X|B]\mathbb{E}[1]= \mathbb{E}[X|B](1)= \mathbb{E}[X|B]$$
