$\lim_{n \to \infty} x_n = 0$ and $\lim_{n \to \infty} f(x_n) = a$ Let $f(x)$ be a continuous function defined on $(0,1]$. Define a  subset $I \subseteq \Bbb R$ as follows: $a\in I$ if and only if there exists a sequence in the interval $(0,1]$ such that $\lim_{n \to \infty} x_n =0$ and $\lim_{n \to \infty} f(x_n) = a.$

I want to show that in general, if $I$ is nonempty, then it is a connected closed set.

When $f(x)$ is $\sin1/x$, I think $I=[-1,1]$ by seeing graph. (I was taught this by Elliot G.). More precisely,by taking $x_n＝1/2nπ ,y_n＝1/（２nπ＋1/2）$,we can check $1,-1∈I$.In the same way, for arcitrary a∈[-1,1],we just need to let $x_n＝1/（２πn＋arcsina）$.
But in general, I cannot show $I$ is connected closed set in real line.
According to Michael, we just need to show $ let a,b∈I,a＜b,c∈（a,b）,
then, c∈I$. I understand that, but I don't know how to apply intermediate value theorem in this situation. Thank you.
For connectivity, apply the intermediate value theorem. Suppose that $x, y \in I$ and without loss of generality take $x &lt; y$. Then there exist monotonically decreasing sequences $x_n$, $y_n$ converging to $0$ so $\lim\limits_{n \to \infty} f(x_n) = x$, $\lim\limits_{n \to \infty}f(y_n) = y$. Using terms from these sequences, one can form a decreasing sequence $z_n \to 0$ so that $\lim\limits_{k \to \infty}f(z_{2k}) = x$ and $\lim\limits_{k \to \infty}f(z_{2k+1}) = y$. Now fix $\alpha$ so $x &lt; \alpha &lt; y$. We can find a sequence of real numbers $\alpha_k$ so that for all $k$, $f(z_{2k}) \leq \alpha_k \leq f(z_{2k+1})$ and $\lim\limits_{k \to \infty}\alpha_k = \alpha$. Continuity of $f$ and the intermediate value theorem provide us a decreasing sequence $\tilde{z}_k \to 0$ so $f(\tilde{z}_k) = \alpha_k$. We conclude that $\alpha \in I$, so $I$ is connected.
To see that $I$ is closed, take $\alpha \in \mathbb{R}$ and a sequence $\alpha_k$ in $ I$ converging to $\alpha$. By the definition, we get decreasing sequences $x_{k, n}$ so that $\lim\limits_{n \to \infty} x_{k,n} = 0$ for all $k$ and $\lim\limits_{k \to \infty } f(x_{k,n}) = \alpha_k$ for all $k$. With this one can inductively construct a decreasing sequence $x_k$ converging to $0$ so that $|f(x_k) - \alpha_k| &lt; \frac{1}{k}$. One can then see that $\lim\limits_{k \to \infty}f(x_k) = \alpha$, so $\alpha \in I$ completing the proof.
One should note that $I$ need not be a closed interval. The function $f(x) = \frac{1}{x} \sin(1/x)$ is an example where $I = \mathbb{R}$.
Assume $a \notin I$.  Then $\exists \varepsilon \gt 0$ such that $\{ x \mid \vert f(x) - a \vert \lt \varepsilon \}$ is finite.  But then there must be an open ball around $a$ for which the same statement is true:  If $\vert y - a \vert \lt \frac {\varepsilon}{2}$, then $\{ x \mid \vert f(x) - y \vert \lt \frac {\varepsilon}{2} \} \subseteq \{ x \mid \vert f(x) - a \vert \lt \varepsilon \}$ is finite (because it's a subset of a finite set), so also $y \notin I$.  Therefore $\Bbb R \setminus I$ is open, and $I$ is closed.
Alex Nolte's proof demonstrates that $I$ must be connected.