Basic prime check doubt

Why is the first if block written within the while loop where else the second one (for prime) written outside it.

the first if block is inside the while loop because at the time we found any integer less than ā€˜nā€™ which divides n we can print that its not a prime and come out of the loop immediately.
if no integer divides n except the no. itself so to check that condition a if statement is written outside the loop.
hope you found that helpful.