Can anyone suggest a better alternative?
Yes. Don’t do this at all. Just use the while
and if
statements directly.
When you’re programming in C or C++, program in C or C++. While until
and unless
might be used frequently and idiomatic in some languages, they are not in C or C++.