Correcting a comparison mistake in the for loop