|
|
|
|
|
by kevinkemp
5387 days ago
|
|
Although your point on efficiency stands (at least with data structures that have to reshuffle contents on deletion), the type of loop that you use has nothing to do with the order that you delete the elements. You could easily do something like: while (MyControl.TabPages.Count > 0) {
MyControl.TabPages.RemoveAt(MyControl.TabPages.Count-1);
} For loop are nothing more than while loops with: (1) an assignment (int i = MyControl.TabPages.Count in this case) (2) an extra command (i-- in this case) added to the end |
|
Regarding for vs while, I find the choice is important only in the intent they emphasize: while puts emphasis on the condition, whereas for puts the emphasis on the iteration. I think in this case the condition (that the list is not empty) is deserves more emphasis than the iteration through the elements of said list - hence why I find the while version to be more readable. YMMV and all that :)