Doubt in itr loop!

Why here itr starts from 1 and not from 0 ??

Hey @piyushkumar999999
We started the variable itr from 1 not from 0 because we know that after the first itr we need not check the last element and it will get largest element on its own. Last element is 1st from last that’s why we started from 1 because it will get sorted automatically. starting from 0 makes no sense because last 0 sorted elements doesnt mean anything. Moreover you are swapping jth and(j+1) th element so if you go on last element …with which element will it get swapped.

Hey @piyushkumar999999
I think my explanation was enough already on it :slight_smile:

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.