The output i need

> 
> enter name: john
> 
> 
> 

> 
> name not found in array
> 
> 
> 

Here is my pseudocode

```
//ask for name
System.out.print("enter name")
name = sc.nextLine()

//loop to check if name exists in my array
for (int count = 0; count < arrayofnames.length; count++)
{ 
    if (name.equals(arrayofnames[count]))
    { code to be executed if name is found in arrayofnames }
}

```

I tried putting an else/else if condition after the if but it executes the code arrayofnames.length times. How do I only make it print something like "name not found in array" only once then break?
['https://Stackoverflow.com/questions/68172043', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/16306518/']
You can have a flag, which you can test after the loop

```
System.out.print("enter name")
name = sc.nextLine()

boolean found = false;

for (int count = 0; count < arrayofnames.length; count++)
{ 
    if (name.equals(arrayofnames[count]))
    { 
        found = true;
        break;
    }
}

if (!found) System.out.println ("Not found");

```
```
public static void main(String[] args) {
        String name = "jhn";
        String[] arrayofnames = {"john", "tomer", "roy", "natalie"};
        IsName(name, arrayofnames);

    }
    public static void IsName(String _name, String[] _arrayofnames){
        boolean a = false;
        for (String name : _arrayofnames) {
            if(name == _name){
                System.out.println("name is in the array");
                a = true;
            }
        }
        if(!a){
            System.out.println("name is not in the array");
        }
    }

```