I'm new to Java and I'm trying to understand how to nest an if statement inside a for loop and have it exit the for loop once the if statement is executed. I have an array, the for loop goes through the array to see if an ID exists, if it does its supposed to delete it, if it doesn't exist then it should print an error message. What is happening is the condition is test in the nested if statement in the while loop and printing the error message 3 times. I would like it to only print the error message once.
In my main method I have
remove("3");
remove("3");
on the first one it should just remove that ID and print that it was rem, the second one it should only print the error message once. This is a project for school and requires no input from a user. I'm just trying to understand how to make this work without printing out repeat error messages
public static void remove(String studentID) 
{
    for (int i = 0; i < thestudents.size(); i++) 
    {
        Student temp = thestudents.get(i);
        if (temp.getStudentID()==(Integer.parseInt(studentID))) 
        {
            thestudents.remove(i);
            System.out.println("Student " + temp.getFirstName() + " was removed");
        }
        else
        {
            System.out.println("Student with ID " + studentID + " Was not found!");
        }
    }
}
The result:
Student with ID 3 Was not found! Student with ID 3 Was not found! Student Jack was removed Student with ID 3 Was not found! Student with ID 3 Was not found! Student with ID 3 Was not found! Student with ID 3 Was not found! Student with ID 3 Was not found!
Expectation:
Student Jack was removed Student with ID 3 Was not found!

