$f:[a,b]\to \mathbb R$ is continuous iff graph of $f$ is connected and closed. [duplicate]

I found a problem in Makarov's book which is as follows:

Prove that $f:[a,b]\to \mathbb R$ is continuous iff graph of $f$ is connected and closed in $\mathbb R^2$.

I am concerned with the if part.I have started with the contrapositive.Let $c$ be a point of discontinuity of $f$ .So there exists a sequence $(x_n)\to c$ such that $f(x_n)\not\to f(c)$.But then I got stuck.Please give me some suggestions.


If $f$ is continuos then $Id\times f: [a,b]\times [a,b]\to [a,b]\times \mathbb{R}^2$ is continuos. However $[a,b]\times [a,b]$ is connected and so also the image of $Id\times f$ is connected , that coincides with the graph of $f$.

Let us consider a sequence $(x_n,f(x_n))$ convergent to $(x_0,y_0)$. Then

$x_n\to x_0$ and $f(x_n)\to y_0$

However $f$ is continuos and so $f(x_n)\to f(x_0)$. The limit have to be unique and so $y_0=f(x_0)$, I.e $(x_0,y_0)$ belongs to the graph of $f$. Thus the graph of $f$ is also closed.

Now let us suppose the graph of $f$ is connected and closed. We have to prove that $f([a,b])$ is bounded. By contradiction there exists a sequence $x_0$ such that $f(x)\to \infty$ for $x\to \infty$. Then you can choose a little ball centred on $(x_0, f(x_0))$ such that intersects the graph of $f$ only in that point. So $\{(x_0,f(x_0))\}$ is closed and open set of the graph, that is not possibile because the graph of $f$ is connected. This means that the image of $f$ is bounded. Taking a sequence $x_n\to x_0$, then $f(x_n)$ is bounded, and so admits a convergent subsequence to some $y_0$. Then $(x_n,f(x_n))$ converges to $(x_0,y_0)$ but the graph is closed and so

$y_0=f(x_0)$