How do I add many fields in a form?

How do I add many fields in a form?

Hello everyone, 

I have a form, and in the form i have some sections, In each section I have the sum of the fields that section has, i was addend that fields, it was only 3, so add 3 fields is easy using conditions, like:

if(input.field1 > 0) && (input.field2 > 0) && (input.field3 > 0){
      input.total = input.field1 + input.field2 + input.field3;
}

As you can see, i can do it, but i have to put every condition in every "On user input" so, in case that field2 == null, do this.. in case that field1 == null and others are > 0 do that.. and you know, it's tedious, i can do it but it's tedious.

so this is my question, if i have a section of the form that i have to add 8 fields, i have to do like 50 conditions in every case and it's not the objective, i want to know, or someone can help me to know what can i do, to add these sections and do not end doing like more than 200 if conditions, help me please!!