@asu ... see .. suppose our array is - 1, 2, 3, 4, 5, 6
and we want to search x=7, then check what happens here-
In the beginning , i=0, and j=5.
k= (0 + 5)/2 = 2.
A[2] <7, so i=k=2.
now while (A[2] != x&& i <j) - true
2nd time - i=2, j=5.
k= (2+5)/2= 3
A[3] < 7, so i=k=3
while(A[3] !=x && i<j) - true
3rd time - i=3, j=5.
k= (3+5)/2= 4.
A[4] < 7, so i= k=4.
while(A[4] !=x && i<j) - true
3rd time - i=4, j=5.
k= (4+5)/2= 4.
A[4] < 7, so i= k=4.
while(A[4] !=x && i<j) - true
3rd time - i=4, j=5.
k= (4+5)/2= 4.
A[4] < 7, so i= k=4.
.
.
.
will go into infinite loop.
So to get rid of this infinite loop if we put- i = k+1. instead of i=k then it would not fall into infinite loop.
..
.and you can put j= k-1 and even j=k is also okay.
.