Use begin-end statement to avoid setting initial value of i, compare only once when i == n