AFL

Arguably Functional Language



AFL Documentation

Control Statements


AFL supports a number of what it calls control statements, which are functions that control the normal flow of code. Certain control statements are used with code blocks, which start with the control statement, and end with the use of the end() function. It is required that all code blocks are ended. Code blocks can also be nested. It is customary to indent all code within a code block. This entry lists all control statements, and how they are used. control statements cannot be part of an expression, though their parameters can be made of expressions.

Code Block Creating Control Statements

if(bool)

The if control statement executes the code within its block if its parameter is true. If it is false, the code within its block is ignored and skipped.

else()

The else control statement can only be used after the end of an if statement's code block. The code within its block only runs if the code in the if statement's block did not. Note that any check in an if statement will be run again in the else statement.

while(bool)

The while control statement executes its block of code if the condition is true, similarly to the if statement, but after it reaches the end of its block, it checks the condition again, and will continuing executing the code in its block until it is false.

Other Control Statements

return() and return(value)

The return function is tied to functions. when return is run, the function currently running is stopped, and if any value is returned, it is passed to the code that called the function. For example, imagine you have a function to double a number:

function("double" 1); return(2*arrayGet(params 0)); end()

the return function here will allow us to get the value the function generates.

double(10) # will print "20.0"

break()

The break function only works inside of while loops, and when called, immediately ends running code inside of the loop.

continue()

The continue function only works inside of loops, and when called, returns to the start of the loop.

error(string)

The error function causes AFL to report an error with a description provided by its parameter.