title: Validation with two for loops in servlet not working
body: <p>I am working on a booking application and I want to validate two things. First I want to check if a booking already exists and secondly I want to check if the id number that is entered exists in my database. The problem is that I can't make the two for loops work together. </p>
  
  <p>This is how my code loooks now:</p>
  
  <pre><code>else if(operation.equals("book")){
      String sessionnr = request.getParameter("dropdown");
      String pnr = request.getParameter("pnr");
      url = "/Book.jsp";
  
      if(pnr !=null &amp;&amp; sessionnr !=null){
          boolean p = false;
  
          for(Booking b: facade.getBookings()){
              if(b.getId().getSessionnr().equals(sessionnr) &amp;&amp; b.getId().getPnr().equals(pnr)){
                  feedback = "This booking already exists!";
                  request.setAttribute("feedback", feedback);
                  p=true;
              }
          }
          for(Customer c: facade.getAllCustomers()){
              if(!c.getPnr().equals(pnr)){
                  feedback = "Id no exist";
                  request.setAttribute("feedback", feedback);
                  p=true;
              }
          }
  
  
              if(p!=true){
              facade.createBooking(pnr, sessionnr);
              feedback="You have made a booking!";
              request.setAttribute("feedback", feedback);
              }
  
              ArrayList &lt;Session&gt; list4 = facade.getAllSessions();
              request.setAttribute("sessions", list4);
              url = "/Book.jsp";
      }
  
          }
  
      RequestDispatcher dispatcher =
      getServletContext().getRequestDispatcher(url);
      dispatcher.forward(request, response);
      }
  
  }
  </code></pre>
  
  <p>Why isn't this working? Is there any way to do it without using two for loops?</p>