the if-case is taken only one time in the while-loop, why?

 int iterator = 0;

Did you mean "static"?