if, unless

Prev Next

Function Names

if, unless

Synopsis

if/unless (expression) { statements } [ else { statements } ]
if/unless (expression) statement; else : statement

Description

Executes statement or block after function name if parameter is true (for if) or false (for unless).

Call as: procedure

Restrictions

Indirect parameter passing is disabled

OS differences

None

Parameter count

1

Parameters

No.TypeDescription
1
input
boolean Boolean expression

If the expression is true, then the following statement or block will be executed. Otherwise, it will be skipped.

Default value: n/a

Exceptions

none

Examples

       for (a[] = 0, a[] <= 6, a[]++)
       {
               if     ( even(a[])) echo(a[], " is even" );
               unless ( a[] < 5  ) echo(a[], " is not smaller than 5" );
               else:  echo (a[], " is smaller than 5");
       }

Output

0 is even
0 is smaller than 5
1 is smaller than 5
2 is even
2 is smaller than 5
3 is smaller than 5
4 is even
4 is smaller than 5
5 is not smaller than 5
6 is even
6 is not smaller than 5
Try it yourself: Open LIB_Function_if.b4p in B4P_Examples.zip. Decompress before use.