compute prefix sums as while loops