I just started learning analysis and encountered my first task on continuity today, namely proving that $f: \mathbb{R}\to \mathbb{R}, \space f(x) = \inf\{|x-k\rvert \space \mid k\in \mathbb{Z} \}$ is continuous in every point. I attempted to prove this as follows:
Let $x_{0} \in \mathbb{R}$ be arbitrary. Let $x \in \mathbb{R}$. By the triangle inequality we have $\left|x_{0}-k\right| \leq\left|x_{0}-x\right|+|x-k|$ for all $k \in \mathbb{Z}$. Thus, one obtains $$ \inf \left\{\left|x_{0}-k\right| \mid k \in \mathbb{Z}\right\} \leq\left|x_{0}-x\right|+\inf \{|x-k| \mid k \in \mathbb{Z}\} $$ so by the definition of $f$ $$ f\left(x_{0}\right)-f(x) \leq\left|x_{0}-x\right| $$ so we obtain $f(x)-f\left(x_{0}\right) \leq$ $\left|x_{0}-x\right|$ (applying the same argumentation). We get $$ \left|f\left(x_{0}\right)-f(x)\right| \leq\left|x_{0}-x\right| $$ Now, let $\epsilon>0$ be arbitrary. To show that $f$ is continuous in $x_{0}$ we must find some $\delta>0$, s.t. for all $x \in \mathbb{R}$ with $\left|x-x_{0}\right|<\delta$ the inequality $\left|f\left(x_{0}\right)-f(x)\right|<\epsilon$ holds. From the above we can clearly see that $\delta=\epsilon$ is a sufficient choice is. Since $x_{0}$ was arbitrary, we are done.
Does this attempt seem valid? Also, what are other ways one could prove this (assuming that the above works). I assume that one often can just plug in the definition of the respective function and then rearrange the inequality, but this didn‘t quite work for me in this case.