Printing sum in loop

OP: The first post on this Forum has a subtopic on scope. It might be helpful to read that.