If limit of $f$ is $L$ and limit of $g$ is $M$, then limit of $g$ composed $f$ is $M$? Problem: 
Find examples of functions $f$ and $g$ defined on $\mathbb{R}$ with $\lim\limits_{x\to a}f(x) = L$, $\lim\limits_{y\to L}g(y) = M$, and $\lim\limits_{x\to a} g(f(x))\neq M$. 
I have tried various combinations like $f(x) = x$ and $g(y) = y^2$, $f(x) = b$ and $g(y) = y^2$, and so on. I have even tried with some trigonometric functions with no luck. I am wondering what characteristic am I trying to "break" so that the conditions do not hold. Also, since $f$ and $g$ have to be defined on $\mathbb{R}$, does that mean that something like $\frac{1}{x}=f(x)$ is not a valid example since it is not defined at $x=0$?
Thanks for your help.
 A: The answer probably depends on the definition of limit. I will use the following definition (from Stewart's Calculus):

We say that $\lim_{x\to a} f(x)=\ell$ if for any $\epsilon > 0$, there exists $\delta>0$ such that, if $0<|x-a|<\delta$, then $|f(x)-\ell|<\epsilon$.

$0<|x-a|<\delta$ means that the value of $f$ at $a$ does not matter. $f$ could even not be defined at $a$ at all. In some books the condition is $0<|x−a|<δ$ is changed to $|x-a|<\delta$. In that case, you should have a look to @msm's answer.
If you are using the above definition, then consider $f(x)=\left\{\begin{array}{ll} 1, & x\neq 0 \\ 0, & x=0  \end{array} \right.$ and $g(x)=\left\{\begin{array}{ll} 0, & x\neq 1 \\ 1, & x=1  \end{array} \right.$. Then $\lim_{x\to 0}f(x)=1$ and $\lim_{x\to 1}g(x)=0$. but $\lim_{x\to 0} g\circ f(x)=1\neq 0$.

Note that, if $f$ is continuous at $a$, then $\ell=f(a)$ and 

if $0<|x-a|<\delta$, then $|f(x)-\ell|<\epsilon$

is equivalent to 

if $|x-a|<\delta$, then $|f(x)-\ell|<\epsilon$

since, $|x-a|=0$ means that $x=a$ and in that case, $|f(x)-\ell|=0$.
A: There is no such sequence in continuous functions - but there should be many such examples for functions with discontinuities. The examples you're trying are not working because the functions are continuous everywhere. But, if yo let yourself take a function with some discontinuities, then you should be able to have an example
A: Finding the desired example is not that difficult if one analyzes the given conditions properly. First we analyze $\lim_{y\to L} g(y) =M$. This limit tells us something about values of $g(y) $ for values of $y$ near $L$ but specifically it does not tell us anything about value $g(L) $. So let's define $g$ as $g(L) =N\neq M$ and $g(y) =M$ if $y\neq L$.
Next consider $\lim_{x\to a} f(x) =L$ and we try to find $f$ which takes values equal to $L$ in every neighborhood of $a$. One example is $$f(x) = L+(x-a) \sin\frac {1}{x-a},f(a)=L$$ Now the limit $\lim_{x\to a} g(f(x)) $ does not exist. Why? Because in neighborhood of $a$ we have some values of $f$ equal to $L$ so that $g(f(x)) =N$ for those values of $x$. For other values of $x$ near $a$ we have $f(x) $ near $L$ and therefore $g(f(x)) $ is near $M$. Since $M\neq N$ the limit does not exist.
It is a bit surprising that many answers claim that such examples don't exist.

Always remember the limit rule for composition:

Limit of composite functions: If $\lim_{x\to a} f(x) =L$ and $f(x) \neq L$ as $x\to a$ and $\lim_{y\to L} g(y) =M$ then $\lim_{x\to a} g(f(x)) =M$.

This is a theorem and you won't find counter-examples for it. On the other hand your question misses the important hypothesis $f(x) \neq L$ and thus one can find examples as desired specifically by choosing functions $f$ such that $f(x) =L$ as $x\to a$. 
A: Simply consider $f$ to be the constant function $f(x)=L$, and consider $g(x) = M$ for $x \neq L$ and $g(L) \neq M$.
