Conditional Expressions

If/Unless

MillScript supports "cascaded" if expressions. Here is a schematic outline of the syntax.

if E then S
elseif E then S       # optional
elseunless E then S   # optional
else S                # optional
endif
        

As you can see, the if form is closed with a matching endif. The optional elseif/elseunless branches can be repeated as many times as you like. Note that elseunless E is simply a shorthand way of writing elseif not( E ). If the else branch appears it must be the last of all.

The if form demands a boolean argument i.e. true or false. Nothing else will do.

In addition to the if form there is also an unless form. This form is identical to the first except that the sense of the initial test is negated. In other words, it is the same as if not( E ) then .... Here's an outline of its syntax.

unless E then S
elseif E then S       # optional
elseunless E then S   # optional
else S                # optional
endunless
        

Switch

MillScript also supports switch expressions. Here is a schematic outline of the syntax.

switch E
  case E1 then S1            # optional
  case E2 case E3 then S2    # optional
  else S3                    # optional
endswitch
        

As you can see, the switch form is closed with a matching endswitch. The optional case branches can be repeated as required. In the example statement S1 is executed if E has the value E1. S2 is executed if E has the value E2 or E3. S3 is executed only if E does not match any case expression.