How to tackle limit question using epsilon-delta? Consider the function, with domain $\mathbb{R}$, defined by
$$f(x)
= \begin{cases} 
      x & \text{if $x$ is rational,} \\
      -x & \text{if $x$ is irrational.} 
   \end{cases}
$$
Prove that $\lim_{x\rightarrow 0}f(x)=0.$

Obviously, intuitively, the limit is $0$. But how do I prove this by definition? 

My attempt:
Let $\epsilon>0$. Then $\exists\delta > 0$, such that, if $0<|x-0|<\delta$, then $|f(x)-0|<\epsilon$, i.e.,$|x-0|<\epsilon \Rightarrow |x|<\epsilon$. 
Then, $$|f(x)-0|<\epsilon \text{ iff } |(x)-0|<\epsilon$$
$$|x|<\epsilon$$
Choose $\delta = \epsilon$ it follows that $|f(x)-0|<\epsilon$.

Just want to see if this fulfills the proof. All critiques welcome.

 A: To show the existence of a limit in our case:

We are given $\epsilon > 0$, and we have to find a $\delta > 0$ such that whenever $|x -0| < \delta$ is true, it must also be true that $|f(x) - 0| < \epsilon$. 

I see some problems. For one, how do you go from $|f(x) - 0| < \epsilon$ to $|0-0| < \epsilon$? Note that this is true only if $x = 0$, whereas you need to show that it is true for $|x -0| < \delta$ for some $\delta$.
Note that if for any $\epsilon > 0$ we pick $\delta = 0.5$, then this won't work out. An example is when $\epsilon  = 0.1$ and $x = 0.2$, then while it is true  that $|x - 0| < 0.5$, it is not true that $|f(x) - 0| < 0.1$. Therefore, $\delta = 0.5$ does not work for $\epsilon = 0.1$.
In our case, you believe that you intuitively have got the idea of why the limit is zero. The correct proof is as follows:

Note that $f(x) = x$ or $-x$ depending on some circumstances. Either way, $|f(x)| = |x|$. Therefore, for any $x$ and $\epsilon$, $|f(x)| < \epsilon$ if and only if $|x| < \epsilon$.  Now, if we choose $\delta = \epsilon$, we see that whenever $|x| < \delta = \epsilon$, by the above statement we have $|f(x)| < \epsilon$. Therefore, the limit is established to be zero.

Please read this proof carefully before attempting comments. I would prefer it if you tell me exactly what the problem is.
EDIT : Okay, thank you for the response, now I will show you what exactly the squeeze theorem means.
So let's say we have three functions, $f(x),g(x),h(x)$. Now, suppose there is some point $a$, such that for $x$ "near" $a$ (that is, for $|x - a| < \delta$ for some appropriately chosen $\delta$), $f(x) \leq g(x) \leq h(x)$ is true. This is like putting the graph of $g$, in between both $f$ and $h$. 
Now, suppose that $\lim_{x \to a} f(x)$ and $\lim_{x \to a} h(x)$ both exist and are equal. What does this mean? This means that as $x$ gets closer to $a$, both  $f$ and $h$ get closer to the same point. But what does this imply about $g$? $g$, suffocated between $f$ and $h$, must go to the same point, right? 
That is, a function squeezed between two other functions going to the same point, also must go to that point. This is the essence of the squeeze theorem, whose result would be that $\lim_{x \to a} g(x)$ exists, and equals the limit for $f$ or $h$.
Here, if we take $g(x) = x$ if $x$ is irrational and $-x$ otherwise, then take $f(x) = -x$ and $h(x) = x$, we see that $g$ squeeze between $f$ and $h$, but both $f$ and $h$ have the limit $0$ at $x = 0$, so $g$ must also have the same limit (no $\epsilon-\delta$ business involved here).
The idea with these tricks, is to eliminate your use of $\epsilon-\delta$ arguments for these situations, and come up with more slick proofs. I hope this will motivate you to read further. 
A: Does it have to be an $\varepsilon$-$\delta$ proof? This can be done via the squeeze theorem. In particular, try squeezing your function betweeen $-|x|$ and $|x|$.
By the way, your attempted proof is incorrect, insofar as you're assuming something "then $\exists \delta > 0$ such that..." which really, you're meant to be trying to prove. You can use my answer here to guide you in the writing of these proofs. Though ignored, it's quality is very high.
A: Hint: the absolute value of your function is just the function $g(x)=|x|$. 
The purpose of this hint is that in taking the absolute value of your function (as you do in a delta epsilon proof) and seeking to bound it by a given epsilon, the difference in the functions definition on the rationals and irrationals is lost. 
i.e. take $\epsilon>0$ fixed. Then 
$$
|x|<\delta\implies |f(x)|=|x|<\delta
$$
so it will suffice to take $\delta=\epsilon$.
