update function with while()