Forgot your password?
typodupeerror
Programming

Journal ReciprocityProject's Journal: New While Construct 1

I've been tripping over this issue for a while. I think there should be a do-condition construct. A do-condition construct would be a do-while with multiple conditions, each of which would have its own block if that condition failed. Like this:

int count = 0;

do {
x = normallyDistributedRandomNumber();
} condition( x <= MAX_VALUE && x >= MIN_VALUE ) {
print( "I pick the number: ", x );
} condition( count++ > 50 ) {
print( "I tried fifty times and couldn't pick a valid number!" );
}

Actually, I'm being rather facetious here, and the construct raises all kinds of problems: what if multiple conditions fail, should I execute every block or just the first one? It's wierd having the condition so far away from the main loop. Of course you could just use an if with a break, or a while followed by an if. But then again, I can execute an if with:

boolean b = true;

while( _condition_ && b ) {
_body_
b = false;
}

So if must unnecessary too.

Maybe it should be called do-until instead.

This discussion has been archived. No new comments can be posted.

New While Construct

Comments Filter:

As of next week, passwords will be entered in Morse code.

Working...