DarwinBotsManual
Open the app EspañolES

Flow

cond, start, else, stop and end: the markers that build genes and decide which parts of the DNA run each cycle.

Cost: Flow control; end is free

OperatorWhat it does
condOpens a new gene: empties the boolean stack and starts the condition section, which ends at start or else.
startCloses the gene's conditions and opens its body, which runs if all of them came out true; with no cond before it, it always runs.
elseOpens the alternative body of a gene, which runs when the conditions of the cond came out false.
stopCloses the gene: whatever follows, up to the next marker, is not executed.
endEnds the DNA: whatever comes after it does not run. The engine adds one at the end if you do not.

These words don't calculate anything and don't touch the integer stack: they organize the DNA into genes. The whole DNA is walked, left to right, every cycle, and each marker changes the interpreter's state as it goes by:

Almost every gene has the form cond … start … stop, with else when you need an “otherwise”:

' moves forward while it has more than 2000 energy; otherwise turns
cond
 *.nrg 2000 >
start
 20 .up store
else
 50 .aimdx store
stop

There is no nesting and there are no blocks: the markers are flat. A cond anywhere opens a new gene even if the previous one is missing its stop, and whatever lies outside a gene (before the first marker, or between a stop and the next one) is not executed.

Unlike the rest of the words, cond, start, else and stop are always processed, even when the gene is being skipped, and they charge their cost every time. After each one, the engine records the number of the current gene in .thisgene. end costs nothing: that's where the walk stops.

All of this, with more examples and the numbering of genes, is in Genes: cond, start, else and stop. How conditions combine is in Inline conditions.