Condition in the for loop

It the code for this section in the second function for the for loop we put the condition i<(1<<b), but I’m confused that when will this loop stop because i will always be smaller than 1<<b.

@amanb25 we are incrementing i as i+=1 whereas(1<<b) is constant so why do you think that i will always be smaller,it will become greater than 1<<b after certain point.

Okay yes i get it… thank you :slight_smile:

Yes but suppose as per the question we take b to be the length of the character array, which in this case is 3, so when we left shift by 1 we should get 6 but the loop runs 7 times.

@amanb25 Please explain a lit more what you want to say, i am not getting it.
I would also suggest you to draw and think by writing on paper what cases you are thinking it will fail.
Also remember, here all the numbers till 7 will only be 3 bits long.

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.