Originally Posted by Fraz
I think you need to explain what this "class started off in an invalid state" business is all about.
I don't see a real problem with any of your alternatives. Particularly your last one, or what TheAnimus wrote.
Well, in the first couple of solutions, doStuff() is repeated - hardly ideal, especially when doStuff() may not really be that simple i.e. parameters!
Secondly, if you use an iterator-like approach, which is more or less what I suggested at the end / TheAnimus suggested, this means you have an object which can be passed around but potentially might have unusable values e.g.
If the the first (valid) value that this class might take is [0, 1, 2] (after the first call of ++), what value does it take beforehand? One solution is to rewrite it as an iterator, and have next() and hasNext() methods, but this breaks existing code (or, at least, moreso than other solutions).
The question isn't so much "What is a solution to this problem," rather "What is the best solution to the problem?" - so probably what makes for the clearest code?
isAtEnd just performs a simple integer comparison.