Suppose a continuous function $f : \mathbb{R} \mapsto \mathbb{R} $ such that it has a limit $l$ at $±\infty$.
I had a question that asked me to show that $f$ is bounded on an interval $[-M;M] \subset \mathbb{R}$. To do that I used the fact that $[-M;M]$ is closed and bounded, thus is a compact, and as $f$ is continues, it shows that it is bounded on that interval.
Now it is asked to show that $f$ is bounded on $\mathbb{R}$. I can easily prove the case when $l \not=±\infty$ by using the definition of a limit and the fact that it is bounded on $[-M;M]$.
We have: $\forall \epsilon > 0 \: \exists \delta>0 \: |x-x_0|<\delta \implies |f(x)-l|<\epsilon $
As it's true for all epsilon, it is also true for $\epsilon = 1$. Thus we have: $\exists \delta>0 \: |x-x_0|<\delta \implies |f(x)-l|<1$
Thus we have $(l-1)<f(x)<(1+l)$ Thus $\forall x>x_0$, $f$ is bounded.
Now, as I have shown that $f$ is bounded on all intervals of type $[-M;M]$, we can simply put $x_0=M$, and so $f$ is bounded on the whole $\mathbb{R}$.
I hope this proof is correct. Now what I struggle to understand is how come $f$ can be bounded if $l=\pm\infty$ (there is no condition on $l$, so I suppose it can also denote infinity). Any tips and criticism will be highly valuable.
Your proof looks correct.
Update: As pointed out in the comments and in other answers, actually your proof contains the right arguments, but in the details it is wrong. There should be no such variable $x_0$ in the definition of the limit in $\pm \infty$. If $l \in \mathbf{R}$:
$$\lim_{x \to \infty} f(x)=l \iff \forall \epsilon > 0 \; \exists M \ge 0 \; \forall x > M \; |f(x)-l| < \epsilon$$
$$\lim_{x \to -\infty} f(x)=l \iff \forall \epsilon > 0 \; \exists M \le 0 \; \forall x < M \; |f(x)-l| < \epsilon$$
Taking $\epsilon=1$ in the previous definitions gives you two reals $M_1 \ge 0$ and $M_2 \le 0$ s.t. $|f(x)-l|<1$ if $x<M_2$ or $x>M_1$. $M_1$ and $M_2$ may be different, but taking $M=\max(M_1, -M_2)$, you get that $|f(x)| \le 1+l$ for all $x \in \mathbf{R} \setminus [-M, M]$. Now you know how to end the proof.
Note that the exact argument should be something like $f_{|\mathbf{R}\setminus[-M,M]}$ and $f_{|[-M,M]}$ are bounded, so $f$ itself is bounded.
If $l\in\{-\infty, +\infty\}$, then $f$ is not bounded, almost by definition. The theorem is true only if $l\in\mathbf{R}$.
For the record, $f$ is not bounded iff. $\forall M \ge 0, \exists x\in\mathbf{R}, |f(x)|>M$. It is possible to prove this statement in the case $f(x) \to \pm \infty$.