Can you explain what happens when the code is executed? What does the code do that is wrong?
What should the code do?

The posted code is not complete and wouldn't compile for testing.