Mel - Maya Embedded Language

Relational Operators

Relational operators are used to compare two values and perform an action based on the given results.

if ()

could be read as:

if (comparison of two values)
do operation;

Take the following example.

int $a = 15;
int $b = 6;
int $c = 0;

if ($a > $b)
      {$c = $a - $b;}

print $c;
the if statement checks to see if $a is larger than $b if the comparison is true. We change the value of $c. Note: if you have one operation after the comparison then you do not need the curly brackets {}.

if you wanted to add in an option if the condition fails you could use the else command.

int $a = 15;
int $b = 6;
int $c = 0;

if ($a > $b)
      {$c = $a - $b;}
else
      {$c = $a * $b;}

print $c;

<Top>