First of all I want to say I know there are tons of proofs around there for this theorem, so I'm not asking for a proof. I tried to prove it using my intuition of why it must hold but I'm missing the justification of one fact which I believe it must be true.
Let's say $f$ is a continuous real function defined in a compact set $X \subset \mathbb{R}$, I know it must attain a maximum and a minimum somewhere in the domain, so there is a maximum distance $h$ between $f(x)$ and $f(y)$ for any $x,y \in X$. Now, if we choose $\epsilon>h$ then any $\delta$ would do the job, and if $\epsilon \leq h$, we define $p=\min \{|x-y| : x,y \in X \land |f(x)-f(y)| \geq \epsilon \}$ and we take $\delta= p (\epsilon /h)$, and we would have $\delta \leq p$ and because of that $|f(x)-f(y)|< \epsilon$ whenever $|x-y|<\delta$ (otherwise $p$ wouldn't be the minimum $|x-y|$ satisfying $|f(x)-f(y)|\geq \epsilon$).
This argument seems right to me (is it?) but I still need to justify that $p$ is well defined. I know that if there is indeed a minimum value of $|x-y|$ for which $|f(x)-f(y)|\geq \epsilon$ then it is non-zero and intuitively the reason I see of why it can't approach zero is because in that case the function would blow up somewhere in the domain, i.e. there would be some vertical asymptote and hence the function wouldn't be continuous. I'm asking fore some advice on how to formalize (in the simplest way possible) this reasoning.
Thanks in advance