  A while loop tests a termination condition on every iteration. On a quantum
computer, such measurements perturb the evolution of the algorithm. We define a
while loop primitive using weak measurements, offering a trade-off between the
perturbation caused and the amount of information gained per iteration. This
trade-off is adjusted with a parameter set by the programmer. We provide
sufficient conditions that let us determine, with arbitrarily high probability,
a worst-case estimate of the number of iterations the loop will run for. As an
example, we solve Grover's search problem using a while loop and prove the
quadratic quantum speed-up is maintained.
