Fixed mistake in the while loop code