Stopped second-moment identity for a simple symmetric random walk
= Stopped second-moment identity for a simple symmetric random walk
If $T$ is a stopping time with finite mean, then
$$
\mathbb E[S_T^2]=\mathbb E[T].
$$
Stopping first at $T\wedge n$ and using the $L^2$ martingale convergence theorem justifies passage to an unbounded $T$.