aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Kathy Sierra doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Kathy Sierra doubt" Watch "Kathy Sierra doubt" New topic
Author

Kathy Sierra doubt

Jacob Sonia
Ranch Hand

Joined: Jun 28, 2009
Posts: 174


how will case 0 end in an endless loop
Brij Garg
Ranch Hand

Joined: Apr 29, 2008
Posts: 234


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

Harpreet Singh janda
Ranch Hand

Joined: Jan 14, 2010
Posts: 317

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

Joined: Feb 21, 2010
Posts: 13
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.
 
wood burning stoves
 
subject: Kathy Sierra doubt