title: How do I only print statement once in a while loop?
body: <pre><code>  {
    System.out.println("Enter input file name:");
    Scanner keyboard = new Scanner(System.in);
    String fileName = keyboard.nextLine();
    File read = new File(fileName);
    Scanner inputFile = new Scanner(read);
  
    if(read.length() == 0)
    {
       System.out.println("empty file");
       return;
    }
  
    inputFile.useDelimiter(":");
    String name, code, line, distance;
    System.out.println("Enter station name");
    String stationName = keyboard.nextLine();
  
  
    while(inputFile.hasNextLine())
    {
      name = inputFile.next();
      code = inputFile.next();
      line = inputFile.next();
      distance = inputFile.nextLine();
  
       if(stationName.equalsIgnoreCase(name))
       {
          System.out.println("Station code: " + code + " name: " + name);
          System.out.println("distance " + distance + " kms, is on the " + line + " line");
       }
  
       else if(!stationName.equalsIgnoreCase(name))
       {
          System.out.println("No information was found for station " + stationName);
       }
  </code></pre>
  
  <p>As you can see the final line of code will be printed out multiple times for however many lines of code there are in the text file. Is there any way to make this only print once?
  Thanks in advance.</p>