On what condition does the program terminate?

string s = “bca”;

do {
cout << s << ’ ';
} while(next_permutation(s.begin(), s.end()));

cout << s;

I figured out the output of the program but I am not able to understand how it terminates.

hello @ritkumar

if next larger permuatation doesnt exist then in that case ,next permuation will return false and ur while loop will stop .

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.