Simplified example

(Caution: UNTESTED!)
The example made little sense. 

The Undo stack was used to run the commands, not just undo them. Renamed.

The commands had names, for no reason. They are now added directly to the stack.
The stack was edited (popped) while it was being iterated. The cmd variable was unused. Replaced with simple iterator.

The stack should be undone in reverse order. reversed() added.

The comments had grammatical errors. Corrected.