Does this proof work for the above problem:
Suppose on the contrary that $f$ is not bounded above on $[a, b]$. Then there exists a sequence $x_n$ chosen from $[a, b]$ such that $f(x_n)>n$ for every $n\in\mathbb{N}$. By the compactness of $[a, b]$ there is a subsequence $x_{n_k}$ of $x_n$ such that $x_{n_k}\to c\in[a, b]$. But then we have $f(x_{n_k})\to\infty$, since $f(x_n)$ does, but also $f(x_{n_k})\to f(c)$ by continuity. Since $f(c)$ must be finite, this is a contradiction. Hence $f$ is bounded above; do we then have to show it is bounded below?
You should localize $f$ to $[0,p]$ and then $f$ is bounded on $[0,p]$ with bound $M$, and hence on each $[np,(n+1)p]$ for each $n\in{\bf{Z}}$ with the same bound by the periodicity of $f$ because for $x\in[np,(n+1)p]$, $|f(x)|=|f(x-np)|\leq M$. Therefore, $M$ is a bound for $f$ on ${\bf{R}}=\displaystyle\bigcup_{n\in{\bf{Z}}}[np,(n+1)p]$.