How to get the expected time complexity of while loop?
You should calculate the probability that the while loop runs exactly $k$ times, for $k\in\mathbb{N}$.
Then the expected number of loops is $\sum\limits_{k=0}^{\infty}k\times\mathbb{P}(\text{loop runs }k\text{ times})$.