how do the value of ans go to 6 when we give the condition that while ans^2<n and 5 is that number then after it should terminate the loop rather than giving 6 value .
Loop termination problem
Hi @Raghavsingla522 the condition is ans^2 <= n
In the while loop, first the value of ans is incremented to 6, then it fails the condition and comes out of the loop. This is why we take the ans as ans - inc
@Raghavsingla522 do a dry run using pen and paper yourself and then the flow of control will become clear.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.