vipsi - flow control
Author: kio@little-bat.de
Keywords: vipsi shell script interpreter programming

# vipsi - shell and script language

## the built-in words

### flow control (loops, conditions)

#### proc

    proc foo()  { }            procedure foo: no arguments, does nothing
    proc bee(a) { put a }      procedure bee: takes one argument and prints it
    proc x(a,b) {return a+b}   procedure x takes two arguments and returns the sum

#### return [value | reference]

    end function and return result value.
    e.g.: proc geomed(a,b) { return sqrt(a*b); }

#### end

    end of script or end of procedure returning no value.

#### do ... loop

    repeat statements between do and loop.
    e.g.: var i=1; do; put i; while i<10; i++; loop;

#### while num_value

    do ... while num_value ... loop
    repeat statements between do and loop while value is true.
    e.g.: var i=1; do; while i<100; i+=i; loop; log i;

#### until num_value

    do ... until num_value ... loop
    repeat statements between do and loop until value becomes true.
    e.g.: var i=1; do; until i>100; i+=i; loop; log i;

#### exit

    do ... exit ... loop
    exit from do loop.
    e.g.: var i=1; do; if i>100 exit then; i+=i; loop; log i;

#### next

    do ... next ... loop
    immediately jump to start of do loop for another go.
    e.g.: var i=1; do; i+=i; if i<100 next then; exit; log "never seen" loop;

#### if num_value ... [else ...] then

    if num_value instructions [ else instructions ] then
    execute statements only if test value is true.
    optional else branch if test value is false.
    e.g.: if (a>b) return a; else return b; then;

#### try ... [else ...] then

    try instructions [ else instructions ] then

execute instructions with a "safety net": if a runtime error occurs, then the program is not aborted with an error message. the program execution resumes at else (if an else part is given, else at then). in case of an error the variable errorstr is created (if it not already exists) and contains the error message.

try … else … then controls can not be nested (version 0.8.3. will be improved.) though each procedure can contain a new level of handlers.

    e.g.: try
              open "that damn ol' file"
          else
              log "failed: ", errorstr, nl
          then