For example, take number 25. square root of 25 is 5. So any number between 6 to 24 will not divide 25. so no need run loop for these extra numbers.
Suppose here n=19, square root of 19 is 4.35889894 or 4 as integer.
loop will run i=2,3,4.(only 3 times). otherwise you need to run it from 2 to 18 that is clearly wastage of time.
i = 2
while (i <= sqrt(n))
{
if (n % i == 0){
is_prime = false;
break;
}
i++;
}
So by using sqrt(n) you can make your program execute faster.