Corrected ending clause for if and for