Proof of $E(X) = \int_0^\infty (1-F(x)) \ dx$ where $F(x)$ denotes CDF of the random variable $X$ with range $[0, \infty)$

This post gives a proof that the expectation of a positive real-valued random variable $X$ is equal to the integral from $0$ to $\infty$ of one minus cumulative probability of $X$. In symbols,

$$ E(X) = \int_0^\infty (1-F(x)) \ dx. $$

Proof. Denote by $f$ the PDF of $X$, we will start with the right side of the above equation: $$ \begin{align} \int_0^\infty (1-F(x)) \ dx &= \int_0^\infty \left[ \int_0^\infty f(t)\ dt - F(x) \right] dx\newline &= \int_0^\infty \left[ \int_0^\infty f(t)\ dt - \int_0^xf(t)\ dt \right] dx\newline &= \int_0^\infty \int_x^\infty f(t)\ dt\ dx\newline &= \int_0^\infty \int_0^t f(t)\ dx\ dt\newline &= \int_0^\infty f(t)t\ \Big|_0^t\ dt\newline &= \int_0^\infty f(t)t\ dt\newline &=\mathbb{E}(X).\square \end{align} $$