F.E.L.T.

Functionally Equivalent Language Translation

BREAK

(break)            ; unconditional break, just do it.
(break (< x 0))    ; break only if x is less than zero

The BREAK instruction is used to terminate a loop construct early. That is its only purpose. It can also take an optional expression which will cause the break to only happen if that expression is 'true'. The exact meaning of 'true' is of course dependant upon the chosen back-end coder.


The concept of 'breaking' out of a loop is a very common one in many languages and so FELT supports that notion too. It also has CONTINUE in its repertoire which forces the next iteration rather than stops it completely.

Normal usage

The BREAK instruction is very simple, you would normally use it within the context of a loop. The following example shows such a case:

(defvar stuff ["FELT" "is" "cool" "aid.. not!"])
(foreach (stuff item)
  (if (== "cool" item)
      (break))
  // loop body...
)

Looking at PHP rendering of the above code we get this:

$stuff = array("FELT", "is", "cool", "aid.. not!");
foreach($stuff as $item) {
  {if (("cool") == ($item))
    {break;}}
}

And javaScript produces this code:

var stuff = ["FELT", "is", "cool", "aid.. not!"];
for(item in stuff) {
  if (("cool") == (item)) {
    break;
  }
}

Conditional Usage

Pretty much most of the time the BREAK instruction is only required to be executed when some condition is met within the loop and so FELT makes it a little easier by allowing you to combine the conditional test and the break as one instruction.

Here is the above example, this time re-coded to show how to place a conditional test within it. FELT allows any valid expression here, but again the actual target language will be the final arbiter if what compiles / runs or doesn't!

Here it is again:

(defvar stuff ["FELT" "is" "cool" "aid.. not!"])
(foreach (stuff item)
  (break (== "cool" item))
  ;; loop body...
)

Looking at PHP rendering of the above code we get this:

$stuff = array("FELT", "is", "cool", "aid.. not!");
foreach($stuff as $item) {
  {if (("cool") == ($item)) break;}
}

It looks a little different but that's because this time the back-end PHPCoder class took the liberty of writing a little bit of PHP code for itself to get the same effect.

And again, the back-end JSCoder produces this code:

var stuff = ["FELT", "is", "cool", "aid.. not!"];
for(item in stuff) {
  if (("cool") == (item)) break;
}

Again, a slightly different output but functionally equivalent nonetheless.