  | Mailing List | | Home | | Forum Home | | JBoss - Java Application Server | | Tomcat - JSP/Servlet container | | Struts - A MVC web framework | | iText - An open source PDF Java Library | | JDOM - JDOM XML Parser | | JSP - A mailing list about Java Server Pages specification and reference | | J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition | | J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog | | Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology | |
Struts & Hibernate
|
|
|
  | | | Looping... | Looping... 2006-11-09 - By Emmanuel Eze
Back I do not think that there's any problem with your approach. However, for code neatness, I would have written it as:
public boolean find(double searchKey) { boolean flag; for (int i = 0; i < items; i++) { if (values[i] == searchKey) { flag = true; break; } } return flag; }
Ne'Bahn wrote:
> Hi list: > > What are the consecuences of breaking a loop in this manner: > > // items - the number of items on the array > // values - the array itself > > public boolean find(double searchKey) { > for (int i = 0; i < items; i++) > if (values[i] == searchKey) > return true; > return false; > } > > AFAIK when an instance leave a method all variables "dissapear" (stack > flushes, take some air, if they are objects the garbage collector > prepares > for..). The fact is that I don't like to use the "break" keyword so I > want > to know if this way is the same that "break, then return". > > Thanks in advance. > > =========================================================================== > > To unsubscribe, send email to listserv@(protected) and include in the > body > of the message "signoff J2EE-INTEREST". For general help, send email to > listserv@(protected) and include in the body of the message "help". >
-- *Emmanuel Eze* Home Page <http://emma.ukrosoft.com>: http://emma.ukrosoft.com /With the right attitude - we can achieve the seemingly impossible!/
=========================================================================== To unsubscribe, send email to listserv@(protected) and include in the body of the message "signoff J2EE-INTEREST". For general help, send email to listserv@(protected) and include in the body of the message "help".
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta content="text/html;charset=ISO-8859 (See http://ISO-8859.ora-code.com)-1" http-equiv="Content-Type"> <title></title> </head> <body bgcolor="#ffffff" text="#000000"> I do not think that there's any problem with your approach. However, for code neatness, I would have written it as:<br> <br> public boolean find(double searchKey) { <br> boolean flag;<br> for (int i = 0; i < items; i++) {<br> if (values[i] == searchKey) {<br> flag = true; <br> break;<br> }<br> }<br> return flag; <br> } <br> <br> <br> <br> Ne'Bahn wrote: <blockquote cite="mid000e01c70289$400ce330$66d3dcc9@(protected)" type="cite">Hi list: <br> <br> What are the consecuences of breaking a loop in this manner: <br> <br> // items - the number of items on the array <br> // values - the array itself <br> <br> public boolean find(double searchKey) { <br> for (int i = 0; i < items; i++) <br> if (values[i] == searchKey) <br> return true; <br> return false; <br> } <br> <br> AFAIK when an instance leave a method all variables "dissapear" (stack <br> flushes, take some air, if they are objects the garbage collector prepares <br> for..). The fact is that I don't like to use the "break" keyword so I want <br> to know if this way is the same that "break, then return". <br> <br> Thanks in advance. <br> <br> =========================================================================== <br> To unsubscribe, send email to <a class="moz-txt-link-abbreviated" href="mailto :listserv@(protected)">listserv@(protected)</a> and include in the body <br> of the message "signoff J2EE-INTEREST". For general help, send email to <br> <a class="moz-txt-link-abbreviated" href="mailto:listserv@(protected)" >listserv@(protected)</a> and include in the body of the message "help". <br> <br> </blockquote> <br> <br> <div class="moz-signature">-- <br> <b>Emmanuel Eze</b><br> <a title="Emmanuel Eze" href="http://emma.ukrosoft.com">Home Page</a>: <a class="moz-txt-link-freetext" href="http://emma.ukrosoft.com">http://emma .ukrosoft.com</a><br> <font color="#006600"><i>With the right attitude - we can achieve the seemingly impossible!</i></font> </div> </body> </html> =========================================================================== To unsubscribe, send email to listserv@(protected) and include in the body of the message "signoff J2EE-INTEREST". For general help, send email to listserv@(protected) and include in the body of the message "help". <p>
|
|
 |