Skip to content

MvIF#


Conditional statements are used to perform different actions based on different conditions, giving your program the ability to follow or not follow a “branch” of program code.

Syntax
<MvIF EXPR = "{ expression }">

<MvELSEIF EXPR="{ expression }">

<MvELSE> 
</MvIF>

In MivaScript we have the following conditional statements:

  • if expression: execute some code only if a specified condition is true
  • if…else: execute one block of code if the condition is true and another if it is false
  • if…elseif…else: select one of many blocks of code to execute

Attributes#

Attribute Description
EXPR Returns a value interpreted as a conditional expression, typically involving a comparison, string, or logic operator. The expression must evaluate to true for MivaScript to process the code that follows the <MvIF> tag. An <MvIF> tag must have a closing </MvIF> end tag.

Nested Conditionals#

You can nest <MvIF> tags—enclose one inside another. Each <MvIF> tag must have a corresponding </MvIF> end-tag. Indenting nested tags is not required but makes your code more readable.

<MvIF EXPR="{ age GE 17 }">
    This person may be eligible to drive a motor vehicle.<br>
    <MvIF EXPR="{ age GT 80 }">
        This person requires a re-examination.<br>
    </MvIF>
    The license fee is $40.75.<br>
</MvIF>

Examples#

Basic If
<MvIF EXPR="{ condition }">
    Execute the code here if this condition is true, otherwise skip it.
</MvvIF>

In this example the code executed branches based on the system clock’s current hour of the day, where LT means Less Than. See Operators.

If…Else
<MvIF EXPR="{ s.tm_hour LT 12 }">
    Good Morning.<br>
<MvELSE>
    Good Afternoon.<br>
</MvIF>

Multiple conditions can be used to determine which of several blocks of code to execute.

If…ElseIf…Else
<MvIF EXPR="{ g.month LE 3 }">
    First Quarter.<br>

<MvELSEIF EXPR="{ g.month LE 6 }">
    Second Quarter.<br>

<MvELSEIF EXPR="{ g.month LE 9 }">
    Third Quarter.<br>

<MvELSE>
    Fourth Quarter.<br>
</MvIF>