You don't change val0 or val2 (Horrible choice of names BTW) in the loop, so once you're in there, you're never coming out.