// Given N, find the no set bits (No of 1's in binary represenation)

i didnt understand the meaning of for loop

@Shatabhishek
for( ;n>0;n=n>>1){
ans = ans + (n&1);
}

The loop here is used to iterate through all the bits of a number in its binary representation.
Say n=5, its binary representation will be 101
n>>1 = 010
n>>1(again)= 001
n>>1(again)= 000
This loop will run until n>0
While iterating it will check if the current bit is set or not and accordingly increment the ans variable.

Hope this helps :slightly_smiling_face:

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.