On the off-chance that this does work, the code is so tricky you probably shouldn't even think about using it in real life.
I'm willing to accept the possibility that:
S while (!B): T;
is pronounced: "use T as the continue block for a while() loop that controls S."
If it doesn't, then it seems like the colon should be a semicolon, and you're looping over S until B returns TRUE, then calling T.. which a loop-and-a-half doesn't do.
I'm also willing to consider the possibility that the whole statement is somehow the conditional that controls the loop() statement, and could thus be written like so:
loop (; S while (!B): T ; repeat) {
}
but I'm damned if I can see how the conditional in the while() loop drops through to control the loop() statement, and I have no idea why you'd want to call repeat as the loop() statement's continuation routine.
The best way I know to express the loop-and-a-half is:
while (1) {
S; # make a calculation
last if (B); # drop out when the result is right
T; # adjust the parameters for another try
}
which is, at very least, easier to read.
The fact that expressing the idea requires a last statement goes right to the heart of the fight that made Dijkstra's Use of Go To Considered Harmful so infamous.
According to the key theory of structured programming (I don't reall who did the proof and don't have my references with me right now), you can write any program with nested function calls (where each function has a single entry point and a single exit point), while() loops, and if() statements.
The problem is that some forms of logic are extremely ugly when written using only those tools.
We've solved those aesthetic problems by adding things like the next, last and redo statements, continue blocks, else and elsif() statements, the capacity to exit a function from more than one place, and so on.
Technically, those tools exceed the 'minimal effective system' necessary to write programs, but they don't violate the spirit of structured programming, and they make the code a heck of a lot easier to read.
|