I just changed the i=(terms +1) to i<=terms, but it doesn't help.