  | 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
|
|
|
  | | | T
: Looping... | T
: Looping... 2006-11-09 - By ?
Back In my opinion , if (values[i]==searchKey) return true, the method will return true, the last return will not execute.
Winy Wan wanyi@(protected)
__ __
???: A mailing list for Java(tm) 2 Platform, Enterprise Edition [mailto:J2EE-INTEREST@(protected)] ?? Emmanuel Eze ????: 2006?11?9? 18:58 ???: J2EE-INTEREST@(protected) ??: Re: Looping...
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".
=========================================================================== 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".
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft -com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:st1= "urn:schemas-microsoft-com:office:smarttags" xmlns="http://www.w3.org/TR/REC -html40">
<head> <meta http-equiv=Content-Type content="text/html; charset=gb2312"> <meta name=Generator content="Microsoft Word 11 (filtered medium)"> <!--[if !mso]> <style> v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VML);} .shape {behavior:url(#default#VML);} </style> <![endif]--><o:SmartTagType namespaceuri="urn:schemas-microsoft-com:office:smarttags" name="chsdate"/> <!--[if !mso]> <style> st1\:*{behavior:url(#default#ieooui) } </style> <![endif]--> <style> <!-- /* Font Definitions */ @(protected) {font-family:??; panose-1 (See http://ose-1.ora-code.com):2 1 6 0 3 1 1 1 1 1;} @(protected) {font-family:"\@??"; panose-1 (See http://ose-1.ora-code.com):2 1 6 0 3 1 1 1 1 1;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {margin:0cm; margin-bottom:.0001pt; font-size:12.0pt; font-family:"Times New Roman"; color:black;} a:link, span.MsoHyperlink {color:blue; text-decoration:underline;} a:visited, span.MsoHyperlinkFollowed {color:blue; text-decoration:underline;} span.EmailStyle17 {mso-style-type:personal-reply; font-family:Arial; color:navy;} @(protected) Section1 {size:595.3pt 841.9pt; margin:72.0pt 90.0pt 72.0pt 90.0pt;} div.Section1 {page:Section1;} --> </style> <!--[if gte mso 9]><xml> <o:shapedefaults v:ext="edit" spidmax="1026" /> </xml><![endif]--><!--[if gte mso 9]><xml> <o:shapelayout v:ext="edit"> <o:idmap v:ext="edit" data="1" /> </o:shapelayout></xml><![endif]--> </head>
<body bgcolor=white lang=ZH-CN link=blue vlink=blue>
<div class=Section1>
<p class=MsoNormal><font size=3 color=navy face="Times New Roman"><span lang=EN-US style='font-size:12.0pt;color:navy'>In my opinion , if (values [i]==searchKey) return true, the method will return true, the last return will not execute.<o:p ></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=navy face="Times New Roman"><span lang=EN-US style='font-size:12.0pt;color:navy'><o:p> </o:p></span></font>< /p>
<p class=MsoNormal><font size=1 color=navy face=Arial><span lang=EN-US style='font-size:9.0pt;font-family:Arial;color:navy'><o:p> </o:p></span>< /font></p>
<div>
<p class=MsoNormal><font size=2 color=black face="Times New Roman"><span lang=EN-US style='font-size:10.0pt'>Winy Wan<br> <a href="mailto:wanyi@(protected)">wanyi@(protected)</a><br> <br> <o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=black face="Times New Roman"><span lang=EN-US style='font-size:12.0pt'><o:p> </o:p></span></font></p>
</div>
<div>
<div class=MsoNormal align=center style='text-align:center'><font size=3 color=black face="Times New Roman"><span lang=EN-US style='font-size:12.0pt; color:windowtext'>
<hr size=2 width="100%" align=center tabindex=-1>
</span></font></div>
<p class=MsoNormal><b><font size=2 color=black face=??><span style='font-size: 10.0pt;font-family:??;color:windowtext;font-weight:bold'>???<span lang=EN-US>:< /span></span></font></b><font size=2 color=black face=??><span lang=EN-US style='font-size:10.0pt;font-family: ??;color:windowtext'> A mailing list for Java(tm) 2 Platform, Enterprise Edition [mailto:J2EE-INTEREST@(protected)] </span></font><b><font size=2 color=black face=??><span style='font-size:10.0pt;font-family:??;color :windowtext; font-weight:bold'>?? </span></font></b><font size=2 color=black face=??><span lang=EN-US style='font-size:10.0pt;font-family:??;color:windowtext'>Emmanuel Eze<br> </span></font><b><font size=2 color=black face=??><span style='font-size:10.0pt; font-family:??;color:windowtext;font-weight:bold'>????<span lang=EN-US>:</span> </span></font></b><font size=2 color=black face=??><span lang=EN-US style='font-size:10.0pt;font-family: ??;color:windowtext'> <st1:chsdate IsROCDate="False" IsLunarDate="False" Day="9" Month="11" Year="2006" w:st="on">2006<span lang=EN-US><span lang=EN-US>?11< /span></span><span lang=EN-US><span lang=EN-US>?9</span></span><span lang=EN-US><span lang=EN-US> ?</span></span></st1:chsdate> 18:58<br> </span></font><b><font size=2 color=black face=??><span style='font-size:10.0pt; font-family:??;color:windowtext;font-weight:bold'>???<span lang=EN-US>:</span>< /span></font></b><font size=2 color=black face=??><span lang=EN-US style='font-size:10.0pt;font-family: ??;color:windowtext'> J2EE-INTEREST@(protected)<br> </span></font><b><font size=2 color=black face=??><span style='font-size:10.0pt; font-family:??;color:windowtext;font-weight:bold'>??<span lang=EN-US>:</span>< /span></font></b><font size=2 color=black face=??><span lang=EN-US style='font-size:10.0pt;font-family: ??;color:windowtext'> Re: Looping...</span></font><font color=black><span lang=EN-US style='color:windowtext'><o:p></o:p></span></font></p>
</div>
<p class=MsoNormal><font size=3 color=black face="Times New Roman"><span lang=EN-US style='font-size:12.0pt'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=3 color=black face="Times New Roman"><span lang=EN-US style='font-size:12.0pt'>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: <o:p></o:p></span></font></p>
<p class=MsoNormal style='margin-bottom:12.0pt'><font size=3 color=black face="Times New Roman"><span lang=EN-US style='font-size:12.0pt'>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 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 href="mailto:listserv@(protected)">listserv@(protected)</a> and include in the body of the message "help". <o:p></o:p></span></font></p>
<p class=MsoNormal style='margin-bottom:12.0pt'><font size=3 color=black face="Times New Roman"><span lang=EN-US style='font-size:12.0pt'><o:p> </o :p></span></font></p>
<div>
<p class=MsoNormal><font size=3 color=black face="Times New Roman"><span lang=EN-US style='font-size:12.0pt'>-- <br> <b><span style='font-weight:bold'>Emmanuel Eze</span></b><br> <a href="http://emma.ukrosoft.com" title="Emmanuel Eze">Home Page</a>: <a href="http://emma.ukrosoft.com">http://emma.ukrosoft.com</a><br> </span></font><i><font color="#006600"><span lang=EN-US style='color:#006600; font-style:italic'>With the right attitude - we can achieve the seemingly impossible!</span></font></i><span lang=EN-US> <o:p></o:p></span></p>
</div>
</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> =========================================================================== 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>
|
|
 |