Square root question issue

how we can predict that when we come out of the while loop in integer part we would have traversed the number whose square is just less than the given number whose square root we have to find out.can’t it be that we would have not traversed that number and while loop stops at a mid whose square is just greater than the given number ?

if inside the while loop a number occurs whose midmid is greater then e will be decremented to mid-1 immediately and we are not setting ans there
so in this case, either the loop breaks or it goes inside the call and check if for a new mid which is definitely always going to be less than the end
however if we were setting the ans in the condition of greater then yes it would return the integer just greater
consider 17
mid = 17+0 /2 = 8
8’s square = 64>17
so now new end is mid - 1 which is 7
in the next pass 7+0 /2 = 3
3’s square = 9
so currently ans sets to 3 and 0 goes to mid + 1 = 4
now new mid is 7 + 4 / 2 = 5
5’s square 25 -> now read carefully
so here end goes to mid-1 which is 4
and the loop continue with 4 and 4
4
2 = 16 <17
so ans gets set to 4
you see how this worked with 5, immediately decremented and it did not have any effect on previously stored state and then moved on to the next pass

hey @Rj.25 if your doubt is solved, please mark it as resolved