File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Flow Control ( Continue & Break )

 
Tarun Oohri
Ranch Hand
Posts: 189
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not able to get the following code . Its correct answer is " 1 1 3 3 9 9 " .
I know the break statement terminates the on going for loop and shifts the flow to the first statement after the for loop. & continue statement shifts the flow to the next iteration.

Thanks !!!
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tarun Oohri wrote:I know the break statement terminates the on going for loop and shifts the flow to the first statement after the for loop. & continue statement shifts the flow to the next iteration.

That's correct. Now, go through the program line by line in your head, and remember, or write down on a piece of paper, what the value of the variables x and j are at each step. You'll see how the program goes.

You could also run it in a debugger, for example in Eclipse. Set a breakpoint at the beginning of the program and step through the program line by line as it runs.
 
Tarun Oohri
Ranch Hand
Posts: 189
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tarun Oohri wrote:I am not able to get the following code . Its correct answer is " 1 1 3 3 9 9 " .
I know the break statement terminates the on going for loop and shifts the flow to the first statement after the for loop. & continue statement shifts the flow to the next iteration.
Also, if we change " For Each " loop with Basic For Loop...then answer changes to " 1133557799 ".
That it # Contradictory #

Thanks !!!
 
Tarun Oohri
Ranch Hand
Posts: 189
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper de Jong wrote:
Tarun Oohri wrote:I know the break statement terminates the on going for loop and shifts the flow to the first statement after the for loop. & continue statement shifts the flow to the next iteration.

That's correct. Now, go through the program line by line in your head, and remember, or write down on a piece of paper, what the value of the variables x and j are at each step. You'll see how the program goes.

You could also run it in a debugger, for example in Eclipse. Set a breakpoint at the beginning of the program and step through the program line by line as it runs.


Thanks that is a good idea
 
Tarun Oohri
Ranch Hand
Posts: 189
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tarun Oohri wrote:
Jesper de Jong wrote:
Tarun Oohri wrote:I know the break statement terminates the on going for loop and shifts the flow to the first statement after the for loop. & continue statement shifts the flow to the next iteration.


Set a breakpoint at the beginning of the program and step through the program line by line as it runs.


Thanks that is a good idea


Thanks i got it...also got the concept between for & for-each .
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic