8. When tossing a coin once, the probability of getting heads or tails is $\frac{1}{2}$. When the $n$-th toss results in heads, let $a_{n}=1$; when the $n$-th toss results in tails, let $a_{n}=-1$. Also, let $S_{n}=a_{1}+a_{2}+\cdots+a_{n}$, then the probability that $S_{n}=2$ is $\qquad$.
8. When $n$ is even, it is $\frac{\mathrm{C}_{n}^{\frac{n+2}{2}}}{2^{n}}$, and when $n$ is odd, it is 0.

Given that $S_{n}=2$, which means tossing $n$ times, with exactly $\frac{n+2}{2}$ times showing heads and $\frac{n-2}{2}$ times showing tails, we can infer that the integer $n$ must be even. Therefore, the required probability is $\frac{\mathrm{C}_{n}^{\frac{n+2}{2}}}{2^{n}}$ when $n$ is even, and 0 when $n$ is odd.