Loop with recursion

i am facing difficulty in understading loop with recursion
could you give the better explanation for this

this can be best understood by making the recursion tree and trying to dry run for different values of i , j

i`ll explain the recursion tree
i/p -> abc

for(int j = i ; in[j] != '\0'; j++){
   swap(in[i] , in[j]);
permute( in , i+1 ) ;
   swap(in[i] , in[j] ) ;
}

now i = 0
j = 0
swap 0,0
then call permute(in , 1 ) now the for loop starts with j = i so j= 1
swap 1 ,1
call on permute(in , 2) now for starts with j = i so j = 2
swap ( 2, 2) call for i+1 call on permute( in , 3)
now loop does execute
since in[j] == ‘\0’
the char array is still abc
now stack trace is returned to previous state
so now u are on i = 2 , j now increments now in[j] == ‘\0’
so again traced back
now i = 1 j = 2
swap( in[1] , in[2])
calll in permute ( in , i+1) ie permute(in , 2)

and soo on

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.