Can a bounded function always attain its least upper bound on a bounded rectangle in $R^n$? Suppose we have a rectangle $Q$, and $Q\subset R^n$. Then $Q$ is bounded by the definition of higher dimensional rectangles. Suppose $f$ is a bounded function defined on $Q$. Since $f$ is bounded, we can produce its infimum $\inf_Q f$ and supremum $\sup_Q f$. My question is that is it always true that $\exists x_1,x_2\in Q$ with the property that $f(x_1)=\inf_Q f$ and $f(x_2)=\sup_Q f$?
If this does not always hold, please provide an example.

If $Q$ is also closed, then it is compact (Heine-Borel theorem), and thus any continuous function realizes its extrema on it.
If $Q$ is an open rectangle, then for example any coordinate function gives you a counterexample.
If we do not ask $f$ to be continuous, take a countable number of points $\{x_n\}_{n\in\mathbb{Z}}\subset Q$, and consider the function
$$f(x) = \cases{1&if $x\notin\{x_n\}_{n\in\mathbb{Z}}$ or $x = x_0,$\\\frac{1}n & if $x = x_n$ and $n>0$,\\2+\frac{1}{n} & if $x=x_n$ and $n<0$.}$$
It provides a counterexample.
