Given the common while() statement in both do ... while and while loops, and the way the place where a while loop's body would be replaced with a semicolon on a do ... while as if it's a compound statement being turned into an empty statement (or ending the line of a long statement):
Does the syntax in any of the C family languages allow for a "do while and while" loop with both bodies defined?
Presumably the semantics would be a single loop with some operations occurring before the check and some after.
For example:
do {
foo();
} while ( baz() == true ){
bar();
}
foo() would always occur once but bar() would only occur after if baz() returned true.
They cannot be used at the same time. The syntax is either:
while ( expression ) statement
or:
do statement while ( expression ) ;
So you can't do this as in your example:
do {
foo();
} while ( baz() == true ){
bar();
}
But you can come close with this:
do {
foo();
if (!baz()) break;
bar();
} while (1);
You seem to be asking for
do
statement0
while (condition)
statement1
This can be accomplished with:
do
{
statement0
if (!(condition)) break;
statement1
} while (1);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With