once

Prev Next

Function Names

once

Synopsis

once { statements; } else { statements }
once () statement; else: statement
once () { statements; }

Description

Executes the following statement or block only for the first time and once. Further executions of this function will skip that code. This feature is very useful for repeated invocations of code (with start() or include()) or user defined functions and procedures where specific code should executed only once during the first invocation, e.g. blocks where variables are initialized and functions being defined.

Call as: procedure

Restrictions

Indirect parameter passing is disabled

Parameter count

0

Examples

  define procedure ( hi )
  {
      once()
          echo(Hey folks);
      else:
          echo(Good bye);
  }

  // Main program part: Call 'hi' three times:

  hi;
  hi;
  hi;

Output

Hey folks
Good bye
Good bye
Try it yourself: Open LIB_Function_once.b4p in B4P_Examples.zip. Decompress before use.