By now, it has been established that the image of a continuous function over a closed bounded interval is also bounded. The proof given below aims to show that the maximum value is attained at some point, within the bounded interval.
By the earlier result, $\,f$ is bounded. Consider the image of $[a,b]$ under $f$: $$A = f([a,b]) = \left\{f(x) : x \in [a,b]\right\}.$$ $f$ bounded means that $A$ is bounded as a subset of $\mathbb{R}$. We also have that $A\neq \emptyset$.
Since $A$ is bounded and non-empty, there is a supremum: $M=\sup A$. Given any positive integer $n$, $M-1/n$ cannot be an upper bound for $A$. Then there exists some $x_n \in [a,b]$ such that $$M-\frac{1}{n} < f(x_n) \leq M. \tag{$*$}$$ By Bolzano-Weierstrass, $x_n$ has a convergent subsequence $x_{n_{j}} \to x$. Since $a\leq x_{n_{j}}\leq b$, $a\leq x\leq b$. By the continuity of $f$, $\,f(x_{n_{j}}) \to f(x)$. But by $(*)$, $\,f(x_{n_{j}}) \to M$. By the uniqueness of the limit, $\,f(x)=M$.
My problem is with the line marked $(*)$, what in the world guarantees the existence of $x_n$ such that $M-\frac{1}{n} < f(x_n) \leq M$?
Please help me understand the proof, thanks!
The whole argument is actually contained in the proof. Since $M - \frac{1}{n}$ is not an upper bound, there must be an element larger than that, say $f(x_n)$. On the other hand, $f(x_n) \leq M$ because $M$ is an upper bound.