What is the time complexity of the following procedure?

**for** $x \in \{1,\ldots,n\}$: <br/>
$\quad$ $i \gets \lfloor n/2 \rfloor$ <br/>
$\quad$ **while** $i \neq x$: <br/>
$\quad\quad$ **if** $i > x$ **then** $i \gets i -1$, **otherwise** $i \gets i + 1$.


  [1]: https://i.sstatic.net/CZdhv.png
According to me, the time complexity is $O(n^2)$.
The inner while loop starts at $n/2$ and moves towards the value of $x$, worst case it runs $n/2$ times, and best case it runs $0$ times.

> What is the exact time complexity of this procedure?