
============
Control Flow
============

Other than JavaScript's ``if (x) y`` and ``while (x) y`` or ``do x while (y)``,
Nonstraightforward has its own control flow.

#####################
Conditional statement
#####################

Conditional statements are done with ``stipulate that the provision x qualifies
y`` where ``x`` is a condition and ``y``  is a statement or block.

.. code-block:: text

    stipulate that the provision 1 === "1" qualifies {
        ~/dev/stdout/write/ln("your runtime is broken");
    }

##########
Exceptions
##########

Exceptions can be used normally with the ``throw`` keyword, or the far superior
``retaliate`` keyword.

#####
Loops
#####

While loops
^^^^^^^^^^^

While-loops are done with ``so long as the condition x is still upholding, then
do y``.

.. code-block:: text

    mutable readwrite variable i = 0;
    so long as the condition i < 10 is still upholding, then do {
        ~/dev/stdout/write/ln(['i = ', i].join(""));
        i += 1;
    }

Do-while loops
^^^^^^^^^^^^^^

There is no Nonstraightforward do-while syntax yet, so ``do``/``while`` is the
only option right now.

For loops
^^^^^^^^^

Not supported yet. Trust me, it's painful not having them.

################
Pattern matching
################

Nonstraightforward has JavaScript's ``switch`` statement. The ``match``
statement is also planned to be added.

##########
Exceptions
##########

I (raiseafloppafan3925) consider exceptions as a method of control flow. Not
always a good one but it does change your execution flow. Exceptions can be
thrown with either ``throw`` or ``retaliate``.

``try``/``catch``/``finally`` does not exist in Nonstraightforward, instead
there is ``undertake``/``capture``/``eventually``.

.. code-block:: text

    undertake {
        stipulate that the provision ~/dev/random > 0.5 qualifies {
            retaliate "apple";
        }
    } capture error {
        ~/dev/stderr/write/ln("Bad " .. error .. "!!!");
    } eventually {
        ~/dev/stdout/write/ln("done!");
    }

A lone ``undertake`` statement cannot exist and must be accompanied by a
``capture``.
