I want to take 5 floats i have in a list, and add them together.
Calculate5[0] + Calculate5[1] + Calculate5[2] + Calculate5[3] + Calculate5[4]
Is there a more compact way to do this?
variable = Calculate5[0 -+ 4]
Something like this, I know this doesn’t work, just giving an example of what I am looking for
While the way you’re handling it right now is almost definitely the most efficient way to calculate the sum, it also has the least room for variability. Any changes have to be made all five times by hand.
If you intend to do more with the array than adding 5 values together (for instance, adding an arbitrary number of values together), it might look more like:
float sum = 0;
for(int i = 0; i < Calculate5.Length; i++)
{
sum += Calculate5[i];
}
Using @Eno-Khaon 's idea, i was able to come up with an idea that works