Doubt in the termination of while loop

string s = “bca”;

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

cout << s;
What is the output of the given code?

Here how the while loop stops “cba”?

the next_permutation function returns a false ,when the o/p of the next permutation formed is lexicographically smaller than the previous one.

for this example

bca -> cab -> cba -> ( then we get) abc
( which is smaller than cba) so false is returned inside while and it breaks

therefore we get last returned permutation ie abc