Setbits ans increment

why in the second method, the condition whether n&(n-1) is zero and 1 is checked and the ans is incremented anyways.

n=(n&(n-1));
ans++;
no condition checked whether it is zero or not.

@Divit-Goel-2940158062683318
each time when you do n = n&(n-1) one set bit turns into zero.
we dont have to check whether the LSB is zero or one. we just need to count how many times we can do n = n&(n-1)