It is printing the answer n number of times , what is the solution without using while loop

package array;

import java.util.Scanner;

public class online {

public static void main(String[] args) {
	Scanner scn = new Scanner(System.in);
	System.out.println("enter the size ");
	int b = scn.nextInt();
	int [] a = new int[b];
	for(int i = 0;i<b;i++) {
		a[i] = scn.nextInt();
	}
	System.out.println("enter the number ");
	int n = scn.nextInt();
	binarysearch(b,n,a);

}
public static void binarysearch(int b,int n,int a[]) {
int low = 0;
int high = a.length -1;
for(int i = 0;i<b;i++) {
int mid = (low + high)/2;
if(a[mid]>n) {
high = mid -1;
}
else if(a[mid]<n) {
low = mid +1;
}
else if (a[mid]==n){
System.out.println(mid);
}
else {
System.out.println("-1");
}
}

	}
}

Break from the loop once found the solution

where shoud i break?

till else the loop will follow

In the last else if
Also it should be a while loop with the constraint while (low <= high) rather than the for loop

could you pls write the code , because i am not able to understand

it is showing that my program is too slow to execute and it also failed 3 test cases and passed only one

public int runBinarySearchIteratively(
  int[] sortedArray, int key, int low, int high) {
    int index = Integer.MAX_VALUE;
    
    while (low <= high) {
        int mid = (low + high) / 2;
        if (sortedArray[mid] < key) {
            low = mid + 1;
        } else if (sortedArray[mid] > key) {
            high = mid - 1;
        } else if (sortedArray[mid] == key) {
            index = mid;
            break;
        }
    }
    return index;
}

please close this doubt as it has been solved and no new question has been asked for over a week now.