You have a ton of problems with syntax but that aside your logic problems stems from messy seperation of what each loop does.

Outer loop: adds 2 to the term, adds the fac result to the output...