How to get the expected time complexity of while loop? How to get the expected time complexity of while loop below?
While infinity:
  case1: Return 0 with a probability of p(1 - p)
  case2: Return 1 with a probability of p(1 - p)
  case3: otherwise repeat this loop until return 0 or 1

I can understand the probability that this loop runs only one time is $2p(1 - p)$. But I cannot understand how much the expected run time of this is. Can anyone let me know it and why?
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})$.