else without if error



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
.




Relevant Pages

  • Re: else without if error
    ... > looks like correct code to me...what did I miss? ... > public BankAccount searchAccounts (VectorbankAccounts, ... > long accountNumber){ ... > I was also reading about the new for-each style loop in java. ...
    (comp.lang.java.help)
  • Re: Passing NULL Objects
    ... public BankAccount searchAccounts (VectorbankAccounts, long accountNumber){int accNum=0; ... //I want to return the object that matches from the Vector to the calling function else return ?? ...
    (comp.lang.java.help)
  • Re: else without if error
    ... >public BankAccount searchAccounts (VectorbankAccounts, ... >long accountNumber){ ... Tell your IDE to put {on a new line. ... The visual pattern will make ...
    (comp.lang.java.help)
  • Passing NULL Objects
    ... public BankAccount searchAccounts (VectorbankAccounts, long accountNumber){ ... int accNum=0; ... //I want to return the object that matches from the Vector to the calling function ...
    (comp.lang.java.help)