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

Kathy Sierra doubt

 
Jacob Sonia
Ranch Hand
Posts: 179
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


how will case 0 end in an endless loop
 
Brij Garg
Ranch Hand
Posts: 234
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Because whenever x is 10000001 then it again set to 10. Also break in not in the for loop

 
Harpreet Singh janda
Ranch Hand
Posts: 317
Eclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If we are not providing the curly brackets after for loop and Scope of loop control (while , do-while,for) and branch control (if) structure is till next line of the structure.

So here the scope of for loop will be till the if condition not till break. It is same as:



Because the control will never come out of the loop if will result in an endless loop.
 
Abhishek Sawant
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brij is correct. check the condition in for loop, it is always true. Whatever may be the value of x, it is always greater than 5. even if the if statement turns true, value is again greater than 5.
So, condition in for loop will never fail & case 0 will result in infinite loop.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic