- Home /
How to add multiples variable ints from a foreach loop
I can't think a way of adding the multiples ints returned from the foreach loop.
on the image above you can see that the foreach loop, loop through a set amount of childs and then returns the "SubConta" int from each child, but then i can't think of a way to add all those returned ints from the loop to result a total from them.
calculate.png
(5.4 kB)
Comment
Answer by WarmedxMints · Mar 26, 2019 at 04:12 PM
You just want to get the ints and add them all up? If so, just add to an int from outside the loop.
var total = 0;
foreach(Transform child in Lineholder.tranform)
{
var linha = child.GetComponent<Linha>();
if(linha != null)
{
total += linha.SubConta;
}
}
Debug.Log(total);
Your answer
Follow this Question
Related Questions
How do I get this code to run specified amount of times 1 Answer
Large matrix formation and multiplication 0 Answers
Mathf loop between 2 floats? 1 Answer
Unity Float to db 2 Answers
How to get 0-360 degree from two points 2 Answers