esolang

Do-if

Every block starts with do, and you only learn at its end whether it runs once, never, or again and again.

Martsadas, 2021 · Turing complete: yes · ●○○ easy · esolangs.org

Tested with 6 known programs · Test method

Run it

Expected: Hello, World!

The idea

Martsadas made Do-if in 2021. It has five instructions. let sets a variable, PRINT writes values, INPN reads an integer, and the only two blocks are do ... if and do ... while. The joke is the order. Every block opens with do, and the condition that decides whether it runs at all comes after it.

Read the story

The specification leaves open when the condition is tested. This implementation tests it before the block, which if needs anyway. The truth machine needs the same of while. On 0 it prints the 0 once, where a block run first would print it twice.

The machine

StatementDoes
let $x = eSet a variable
PRINT {e, e, ...}Print the values, with nothing between them and no line break
do ... if eRun the block once if e holds
do ... while eRun the block as long as e holds
INPN {}Read an integer

Values are integers of any size and strings in single or double quotes, with \n, \t and \\. Expressions have + - * / and the comparisons = < >, which give 1 or 0. A condition holds unless it is 0 or an empty string. Statements need no separator, as each one starts with a keyword.

Example

The specification writes its strings in single quotes.

The specification writes its strings in single quotes. These use double quotes, which the language allows too, so the shell can keep the program in single quotes.

Expected: odd

The factorial. Its integers do not overflow, so 20 factorial comes out whole.

Expected: 20! = 2432902008176640000

The truth machine, on 0.

Expected: Please input 0 or 1: 0

Further

Also in Jokes

Write your own in Run Convert a program from Do-if

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: do-if.

Command line

shib run do-if -e 'PRINT {'\''Hello, World!\n'\''}'
shib manual do-if

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/do-if.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org