My question is, how can i stop the for loop from executing the else statement every time it cannot find a match for the searchInput? even if the for loop found a match for searchInput the for loop still executes the else statement. how can i deal with this?
here's my original code:
// The For loop executes the Else statement until a match is found for the if statement, how can i deal with this? public void searchBook() { String searchInput = JOptionPane.showInputDialog(null, "Enter Search Query: ", "Book Search", JOptionPane.INFORMATION_MESSAGE); int x; try { for(x=0 ; x<bookName.length ; x++) { if(searchInput.equalsIgnoreCase(bookName[x])) { JOptionPane.showMessageDialog(null, "Book Found !" + "\nTitle: " + bookName[x] + "\nAuthor: " + bookAuthor[x] + "\nPublisher: " + bookPublisher[x] + "\nBook ISBN: " + bookID[x] , "Book Search", JOptionPane.INFORMATION_MESSAGE); } else { JOptionPane.showMessageDialog(null, "BOOK NOT FOUND !" , "Book Search", JOptionPane.ERROR_MESSAGE); } } } catch(Exception e) { } }
thanks in advance...