Is $\lim_{n\to \infty}f(x_n)=f(\lim_{n\to \infty}x_n)$ always true? I was studying about sequences of numbers and their limits. My book states the standard rules for algebra of limits involving sums, differences, products and quotients of convergent sequences.
But the author, while solving an example problem implicitly used the fact that
$$\lim_{n\to \infty}\sqrt{\frac{1}{n+1}} = \frac{1}{\sqrt{\lim_{n\to \infty}(n)+1}}=0$$ 
But my question is can we generalise this result to be applicable to all types of functions...
I found this answer for composite functions - limit of composite function underlying principles and special cases
But since the definitions of limits of number sequences and limit of a function are different, how do we formally prove the following result (this is not a composite function as such..)?
$$\lim_{n\to \infty}{f(x_n)}=f(\lim_{n\to \infty}{x_n})\ \ where  \ \ n\in \mathbb N$$
Here $x_n$ is a sequence of real numbers and its range is contained in the domain of $f$. Also, is this result applicable in all cases..if not...when can it be used..
I am specifically looking for a formal proof of the statement..in those cases where it is applicable
Thanks for any answers!!
 A: Here's a counter-example to show why you need continuity.  Let $f(x)$ be $0$ if $x$ is rational, and $1$ otherwise.  Let $x_n = \frac{\pi}{n}$.  Then
\begin{align*}
    \lim_{n\to\infty} f(x_n) &= \lim_{n\to\infty} 1 = 1 \\
    f\left(\lim_{n\to\infty}x_n\right) &= f(0) = 0
\end{align*}
A: This is not always true. Consider the following function:
$$\begin{equation}
f(x)=
\begin{cases}
1, \quad x=0;\\~\\
x, \quad x>0
\end{cases}
\end{equation}$$
Now if you take the sequence $(x_{n})$ such that $x_{n}=1/n$, then clearly $\lim_{n\to\infty}~f(x_{n})=0$, but $f(\lim_{n\to\infty}~x_{n})=1$.
The condition you stated in the question title is actually a definition for continuity. That is, if that condition holds, then $f$ is continuous at $x_{0}\equiv\lim_\limits{n\to\infty}~x_{n}$ (see Elementrary Analysis ed.2,K. A. Ross, Page 124).
A: Suppose $f$ is continuous at $x$ where $x=\lim_{n\to \infty} x_n$ (and assume $x_n\in D(f)$ for all $n\in \mathbb{N}$). Let $\epsilon>0$ and let $\delta>0$ be such that whenever $|y-x|<\delta$, $|f(x)-f(y)|<\epsilon$ (this is the definition that $f$ is continuous as $x$). Now since $x_n\to x$, there exists some $N\in \mathbb{N}$ such that for all $n\geq N$, $|x_n-x|<\delta$. Therefore $|f(x_n)-f(x)|<\epsilon$ (for $n\geq N$). But this is what it means to say that $f(x_n)\to f(x)$
A: Not true in general.  For a simple example, let $f(x)=\begin{cases} x,\,x\ne1\\2,\,x=1\end{cases}$.
  Now consider a sequence converging to $1$, like $x_n=1+1/n$.
There's a limit point definition of continuous functions that you may want to take a look at.  In particular, it's true when $f$ is continuous.
