4 ms·
A generalized version of the while loop was suggested by Edsger Dijkstra. This loop has more than one guard and terminates when all guards evaluate to false. Wi
by augustk 6y ago
A generalized version of the while loop was suggested by Edsger Dijkstra. This loop has more than one guard and terminates when all guards evaluate to false. With this construct the greatest common divisor can be calculated quite succinctly as
WHILE a < b DO
b := b - a
ELSIF a > b DO
a := a - b
END
The Oberon programming language by Niklaus Wirth supports the Dijkstra while loop.
https://miasap.se/obnc/oberon-report.html#sec9.6 https://miasap.se/obnc/oberon-report.html#sec9.6
- whatshisface 6y agoWouldn't that be `else: break` in every other language?
- nils-m-holm 6y agoIn most other languages it would be something like while true do if condition 1 do statements 1 done else if condition 2 do statements 2 done else do break done done
- augustk 6y agoOberon, however, is a purely structured language and has no goto-like statements like "break".