I need to prove this theorem :
Let $X$ be a random variable. Then $|E(X)|<\infty $ if and only if
$$\sum_{n=1}^\infty P(|X|>n)<\infty$$
I understand the proof until somewhere but I have problem understanding where does the following equality come i.e.
$$\sum_{n=1}^\infty nP(n-1<|X|\leq n)=\sum_{n=0}^\infty P(|X|>n)$$
Can someone help me understand why this equality holds.
Noting that, assuming $\mathbb{E}(X)$ is defined, $|\mathbb{E}(X)|<\infty$ if and only if $\mathbb{E}(|X|)<\infty$ suppose $X \geq 0$. Define $(\Omega,\mathbb{P})$ the probability space and suppose $X : \Omega \to \mathbb{R}$ is a random variable, i.e. is measurable and not necessarly discrete.
An easy consequence of Fubini-Tonelli's theorems is that:
$$\mathbb{E}[X]=\int X d\mathbb{P}=\int_0^{+\infty}\mathbb{P}(X>t)dt$$
Thus, if in your case $X(\Omega)=\mathbb{N}$, the last integral simply became the summation you need.
In addition, if $X(\Omega)=\mathbb{N}$: $$\sum_{n=1}^\infty n\mathbb{P}(n-1<X\leq n)=\sum_{n=0}^\infty \mathbb{P}(X>n)$$ holds for the same reasonement.
In fact if $A_n=\{\omega \in \Omega: n-1<X(\omega) \leq n \}$, then
$$\mathbb{E}[X]=\int X d\mathbb{P}=\sum_n \int_{A_n}X d\mathbb{P}=\sum_{n=1}^\infty n\mathbb{P}(n-1<X\leq n)$$
because $X$ is equal to $n$ in $A_n$ because $X(\Omega)=\mathbb{N}$.