else without if error
- From: fb <fb@xxxxxxxxx>
- Date: Fri, 04 Nov 2005 18:45:21 GMT
Does anyone know why i'm getting an 'else' withour 'if' error here? It looks like correct code to me...what did I miss?
//Linear search
public BankAccount searchAccounts (Vector<BankAccount> bankAccounts , long accountNumber){
for(int x=0;x<bankAccounts.size();x++){
if(bankAccounts.elementAt(x).getAccountNumber() == accountNumber){
return bankAccounts.elementAt(x); //return the element
else
return null; //if not found, return null.
}
}
}
I was also reading about the new for-each style loop in java. Is there a way to rewrite the above for statement to use the new loop construct?
ttyl.
fb
--
"Outside of a dog, a book is a man's best friend. Inside a dog, it's too dark to read anyway." - Groucho Marx
.
- Follow-Ups:
- Re: else without if error
- From: Roedy Green
- Re: else without if error
- From: Noodles Jefferson
- Re: else without if error
- From: Andrew Thompson
- Re: else without if error
- Prev by Date: Re: Passing NULL Objects
- Next by Date: Re: Passing NULL Objects
- Previous by thread: Samples for Poseidon, ArgoUML, Rational rose
- Next by thread: Re: else without if error
- Index(es):
Relevant Pages
|