Home arrow static arrow Java Programming [Archive] - Return inside a loop
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Return inside a loop
This topic has 3 replies on 1 page.

Posts:114
Registered: 7/5/04
Return inside a loop  
Jul 20, 2004 8:44 AM



 
Hi

I have a return keyword inside a loop. By running my application and use some prints I notice that the return doesn�t exit the method ,its continue computing until the end of the loop, how come? Im confused?

Thanks
 

Posts:6,750
Registered: 1/25/04
Re: Return inside a loop  
Jul 20, 2004 8:49 AM (reply 1 of 3)



 
Either you're misunderstanding something or there's a bug in your JVM. Unless you wrote your own JVM, I'm going with the former. Could you post the method, complete with your print statements? Remember to use [url http://forum.java.sun.com/features.jsp#Formatting]code tags[/url], and if you don't know how [url http://forum.java.sun.com/features.jsp#Formatting]please ask[/url] rather than posting code without them.
 

Posts:3,534
Registered: 9/30/99
Re: Return inside a loop  
Jul 20, 2004 10:09 AM (reply 2 of 3)



 
your conditional that keeps your return from causing the exit in each loop never comes true--check it out.
 

Posts:3,534
Registered: 9/30/99
Re: Return inside a loop  
Jul 20, 2004 10:10 AM (reply 3 of 3)



 
put a break on the line with your return and you'll find you never execute it.
 
This topic has 3 replies on 1 page.