This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
We know that when a method is invoked the control jumps to the called method and after finishing, the control will reach the same place from where the flow is broken. Since the control flows three times after finishing it comes back three times and gets printed.
Hope this helps. dinesh.
Joined: Nov 15, 2006
Thanks Dinesh. I understand that. But it should have been 1,2,3 right ? I might be totally wrong.
In retry(), if i is less than 3 you call retry() again, so you will never return from a call to retry() until i equals 3. So when i equals 3 you return from retry() and print the value of i (which is 3).
If you want to maintain a different value of i for each call to retry(), then you need to pass i as a parameter Try this