Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception flow control

 
Kedar Dravid
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consider the code below:



O/p: 5
8
I Can't quite figure out how the o/p is
5
8
Could anybody guide me on the flow control in this one?
[ March 07, 2005: Message edited by: Mark Spritzler ]
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First let's put that code inside the CODE tags so that we can read it.

Mark
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK we start with 0

the first if throws an Exception, and it goes to the outer catch, which adds three, making the value 3, the finally is then run to make it 4, and the incrementer of the loop makes it 5.

So now we run the loop for the number 5. It gets passed the two ifs and prints out 5. ANSWER PART I

It then runs the inner Finally, making it 6, then runs the outer finally making it 7, and then the loop incrementor makes it 8.

So now we run the loop for the number 8. It gets passed the two ifs and prints out 8. ANSWER PART II

So the inner finally makes it 9, the outer finally makes it 10, and the incrementer of the loop makes it 11, and therefore does not continue the loop and ends execution.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic