In order to sum up all the leaves of a nested datastructure, you have to look at each and every leaf. This means nested iteration, or in other words, nested looping. Yes, you can hide the looping in recursion, but it's still looping, in a different way. There's no way of getting around the fact that you have to inspect each leaf.
Perhaps you could avoid this step by keeping a running total as you accumulate the leaves into the nested structure. I don't know where you're getting the data that fills this datastructure, but if you find it expensive (from a computational standpoint) to wend your way through the datastructure adding its nodes, try looking at the problem in a way that avoids having to do that. If you can keep a running tally, you save yourself from the looping, at the expense of a little computational work each time you add, remove, or modify an element in the structure.
Dave
In reply to Re: how to avoid nested looping?
by davido
in thread how to avoid nested looping?
by lamp
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |