A function continuous and bounded on a closed and bounded set but not uniformly continuous there I'm reading 'Counterexamples in analysis by Bernard Gelbaum' which has this as one the counterexample
Function is defined on $\Bbb{Q}$$\cap$$[0,2]$ which is closed and bounded set
$ f(x) =
\begin{cases}
0,  & \text{if 0 $\le$ $x$ $\lt$ $\sqrt2$ } \\
1, & \text{if $\sqrt2$ $\lt$ $x$ $\le$2 }
\end{cases}$
I concluded that it is a continuous function since co-domain is {${0,1}$} and $f^{-1}$ {$0$} and $f^{-1}${$1$} are closed in $\Bbb{Q}$$\cap$$[0,2]$ ( i. e. inverse image of closed sets is closed and hence $f$ is continuous )
but I'm facing trouble in proving that it is not uniformly continuous. Please help.
Also author mentioned that field  $\Bbb{Q}$ is not complete and hence we can have such example . If possible then please explain this point also.
 A: Well some minute points regarding continuity of $f$:
You also need to verify that inverse image of all the opens sets viz.$\{\{0\},\{1\},\{0,1\},\emptyset\}$ are all open .
Regarding uniform continuity of $f$:
Since $\Bbb Q$ is dense ,there exists a sequence $x_n\in [0,\sqrt 2]\cap \Bbb Q$ such that $x_n\to \sqrt 2\implies |x_n-\sqrt 2|<\frac{1}{n}\forall n$.
Similarly since $\Bbb Q$ is dense ,there exists a sequence $y_n\in [\sqrt 2,2]\cap \Bbb Q$ such that $y_n\to \sqrt 2\implies |\sqrt 2-y_n|<\frac{1}{n}\forall n$.
Hence $|x_n-y_n|\le |x_n-\sqrt 2|+|\sqrt 2-y_n|\le \frac{1}{n}\forall n$ but $|f(x_n)-f(y_n)|=1$.
NOTE:Since $\Bbb Q$ is not complete hence it has gaps and always such an example is available
A: Your proof for continuity is correct.
Suppose $f$ is uniformly continuous.
Let $d$ be the metric on $[0,2] \cap \Bbb Q$ which is induced from usual metric on $\Bbb R.$
Let $\epsilon = \frac 12$. Then $\exists \delta \gt 0$ such that $d(x,y) \lt \delta \implies |f(x)-f(y)| \lt \frac 12 \; \forall x,y \in [0,2] \cap \Bbb Q.$
Now if we take $x \in [0, \sqrt{2}] \cap \Bbb Q$ and $y \in [\sqrt{2},2] \cap \Bbb Q$ such that $d(x,y) \lt \delta$, then $|f(x)-f(y)|=|0-1|=1 \not\lt \frac 12.$
So our assumption that $f$ is uniformly continuous is false.
