corrected Forloop code