Do loop until failure

From Esolang
Jump to navigation Jump to search

Do loop until failure, or a D-LUF loop is a form of esoteric control flow in programming languages which is essentially a do..while loop where the condition is whether or not an exception is raised in the body. This provides an esoteric method of design, where one must intentionally crash the script to exit a loop.

Meaning

Do loop until failure loops are, essentially, while loops without a condition. The while loop repeats until the code in its body throws an exception.

Crash Handling

Crashes are handled similarly to a Pythonic TRY statement; they don't terminate, or even get thrown.

Examples

An example of a language supporting the D-LUF loop is the esoshell Getchl, which comes bundled with the Walrus Operating System. Getchl contains a command, @, named REDUCE, which repeatedly executes the previous command until it fails. Some examples of this loop's usage are:

  • +@ (add-reduce): Sum the stack, leaving only the sum of all items on the stack on the stack. This can be done with any operation.
  • $@ (drop-reduce): Clear the stack
  • ,@ (input-reduce): Get input character and push on stack until EOF.

Implementations

In Python:

while True:
    try:
        doSomething()
    except:
        break

Ideal:

do {
    doSomething();
} until fail

See Also

Do loop until failure or condition else