You need to sign in to do that
Don't have an account?

Which Loop Is More Efficient?
Which for loop here is more efficient, is there even a difference when it comes to avoiding governor limits?
Task[] tasks = new Task[]{};
for(Integer i=0;i<tasks.size();i++) {
//some code
}
OR
Task[] tasks = new Task[]{};
for(Task activity: tasks) {
//some code
}
The latter loop is marginally more efficient in terms of the "statements executed" limit, but really they're basically the same.
Rich
All Answers
The latter loop is marginally more efficient in terms of the "statements executed" limit, but really they're basically the same.
Rich
What you're saving there is the statements for declaring and incrementing the counter variable.
I'd add that the real impact on governor limits is going to be the code that exists in that loop. If you're executing any SOQL for example, you can be certain you'll hit your query limits.
This for loop changed in all major programmming languages,people suggest that interm of excution second one is best.