A possible job interview question?

(written by lawrence krubner, however indented passages are often quotes). You can contact lawrence at: lawrence@krubner.com

What is wrong with this code?

Here are five lines of code I found during a review not too long ago. This code had been tested and was ready for release.

for ( int i=0 ; i < this.MyControl.TabPages.Count ; i++ )
this.MyControl.TabPages.Remove ( this.MyControl.TabPages[i] );
Feel free to stare at this for a while and absorb the quality.

When I was at school I had an excellent teacher who taught me how to bench-check a loop. The basic idea is to write down the loop variables, their starting values, and then you step through the loop on paper and update these variables by hand to check that everything works as you expect, especially the edge cases.