Control Flow Functions

Prev Next

Introduction

Flow control covers programming language features like branches (if ... lese), loops, etc. Unlike in other common programming langauges, control flow in B4P is implmented as functions which are then called as procedures which will then determine whether to execute the subsequent statements or blocks or not.

For example, a keyword as simple as if() is a B4P function called as a procedure taking one Boolean parameter. It decides whether to execute the next statement or block or not.

B4P provides a large variety of control flow functions, covering:

In case you miss the goto statement, there is a good reason for this. The highly structured B4P interpreter would have faced risky challenge if that statement would have been impleemented. Further more, see the seeparate section on control flow functions for tables where the following functions, mostly loops, are defined:


Procedures and Functions Provided:


conditional branches:
    if
    unless

one-time execution:
    once

alternative execution of code blocks:
    check
    switch
    case

Break and continue cases and loops:
    break
    continue
    break loop
    continue loop
    break case
    continue case
    continue with next case

Repetition loops:
    repeat

Do-loops:
    do

For-loops:
    for

Loops:
    until
    while

For-loop across set elements:
    for all
    for all parameters

For-loop through variables:
    for all variables
    for all variables if existing
    for all variables if existing and valid

For-loop through characters:
    for all characters

defining user procedures and user functions, user-defined function:
    define function
    define procedure
    define procedure and function

Additional function names:
    define additional function
    define additional procedure
    define additional procedure and function

Return from function calls:
    return

Check if function existing:
    function existing
    user function existing
    delete user function

start B4P program:
    start

include B4P program, include library, include libraries:
    include
    get long options
    pause
    stop

Exceptions:
    interactive
    exit
    end
    abort

Throw and catch:
    throw
    catch
    catch if

Invoke exceptions for error messages:
    exception

Null function:
    null

Select parameter based on numeric value in 1st parameter:
    pick
    select

Select parameter based on boolean value in 1st parameter:
    pick if
    select if

Select parameter based on multiple boolean values:
    pick ifs
    select ifs

Select value from variable if existing:
    pick if existing
    pick if existing and valid
    select if existing
    select if existing and valid

Select parameter based on matching corresponding values:
    pick by value
    select by value

Selection based sequence of comparisons:
    compare pick
    compare select

Replacing values and set elements:
    replace if

Call function or procedure by name provided:
    call

Call function for every set element separately:
    deep
    deepr

Execute B4P statements provided:
    exec

Calculate an expression provided:
    calc

compare [function]:
    compare

assign [function]:
    assign

table assign:
    table assign