In my opinion , if (values[i]==searchKey)
return true, the method will return true, the last return will not execute.
Winy Wan
wanyi@china-channel.com
发件人: A mailing list for Java(tm) 2 Platform, Enterprise
Edition [mailto:J2EE-INTEREST@JAVA.SUN.COM] 代表 Emmanuel
Eze
发送时间:
收件人: J2EE-INTEREST@JAVA.SUN.COM
主题: 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@java.sun.com
and include in the body
of the message "signoff J2EE-INTEREST". For general help, send
email to
listserv@java.sun.com and include in
the body of the message "help".
--
Emmanuel Eze
Home Page: http://emma.ukrosoft.com
With the right attitude - we can achieve the seemingly
impossible!
=========================================================================== To unsubscribe, send email to listserv@java.sun.com and include in the body of the message "signoff J2EE-INTEREST". For general help, send email to listserv@java.sun.com and include in the body of the message "help".