Can someone walk me through how to do a proof of the following?
Let $a$ and $b$ be nonzero integers. Use a direct proof to show that if $a|b$ and $b|a$, then $a= \pm b$.
So I know $a,b \neq 0$ in this case. So if I have for example $a=2$ and $b=4$ then $a|b = \frac{2}{4} = \frac{1}{2} = 0.5$ and then $b|a = \frac{4}{2}= 2$.
I'm then a bit lost?
You are confused as to what the notation "$a | b$" means and are confusing it with the fraction "$\frac a b$". "a | b" is a statement. It means "a divides evenly into b". It's not a number. It doesn't have a value. It's simply either true or false. You can not say $2 | 4 = \frac 2 4 = .5$" any more than you can say "my name is fred = 564-11-5298".
$2 | 4$ is true because 2 divides evenly into 4. $4 | 2$ is false because 4 does not divide evenly into 2. $9|12$ is false. And $12|9$ is false. Can you thing of any two numbers where $a|b$ and $b|a$ are both true.
More technically $"a | b"$ means there exist some integer, $m$ such that $m*a = b$.
So if $a | b$ there is some integer, $m$ such that $m*a = b$.
If $b | a$ there is some integer, $n$ such that $n*b = a$.
If both are true then $n*b = n*m*a = a$ so $n*m = 1$ so both $n = 1/m$ is an integer, and $m = 1/n$ is an integer. If $|m| \ne 1$ then $1/m$ is not an integer. So $|m| =1$ so $m = \pm 1$. So $b = m*a = \pm a$.
====
One thing to note: if $a | b$ then $|a| \le |b|$. (Think about it; if something divides evenly into something it most be smaller than than the other thing. Actually you have to prove that.) That should give you a hint, that $a|b$ and $b|a$ implies $|a| \le |b|$ and $|b| \le |a|$.