I have a set of objects I’d like to do some operations on, in the order they’re iterated. After that operation gets called on them, I’d like to perform other operations on them. Basically, the code will look sort of like this:
for(int i = 0;i < myobj.size();i++)
{
myobj.at(i).doSomething();
}
for(int i = 0;i < myobj.size();i++)
{
myobj.at(i).doSomethingElse();
}
This looks kind of ugly to me. How could I rewrite this into something better? The order of the operations should stay the same.
I don’t know what myobj is but if it’s
Iterable, then you could use a foreach loop:If it’s not
Iterable, then making it so might help other code too.