'Is there a way to put a result from a loop, back into the same loop?

In my code, I am trying to filter out lines from a file that met conditions that are written by the user. A simple example would just be saying "red&round", and if written correctly, it would print out "apple". however, right now I am mentally stuck on how to simplify coding this. As of right now, I am only able to print out strings that match one condition, and I end up with either multiple of one string or strings that only match one condition. I feel like I know that I can just make another for loop within the for loop to filter it out eventually, but I feel like that would be a waste of time. Additionally, I have also tried to use while loops but I always ended up with infinite loops. This is my current code (only a snippet, where the main problem is). I am also just starting out in my first java course, and I would really appreciate any hints as to how I can make a simpler code for this problem.

  if (args[1].contains("&")) {

          String[] queryM = args[1].split("&");

          for (int i = 0; i < queryM.length; i++) {

            if (queryM[i].contains("not")) {

              String command = queryM[i].substring(4, queryM[i].length() - 1);

              if(run(lines.get(lineIndex), name(command), cond(command)) == false) {

                System.out.println(lines.get(lineIndex));

              }
  
            }

            else {

              if(run(lines.get(lineIndex), name(queryM[i]), cond(queryM[i])) == true) {

                System.out.println(lines.get(lineIndex));
    
              }

            }

          }
    
        }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source