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");

```
If you want your code more compact, you can also use Streams to check if any element of the array equals the given String like this:

```java
boolean found = Arrays.stream(arrayofnames).anyMatch(n -> n.equals(name));

if(found) {
  //code to be executed if name is found in arrayofnames 
}

```