您可能经常需要程序根据测试某些条件进行决策和更改其行为。例如,仅当值大于 10 时,才打印该值。与大多数语言相同,MEL 也具有 if 控制结构:
if ($x > 10) { print("It's greater than 10!\n"); print("Run!!!\n"); }
if ($x > 10) { print("It's greater than 10!\n"); print("Run!!!\n"); } else { print("It's not above 10.\n"); print("It's safe... for now.\n"); }
if ( $color == "blue" ) print("Sky\n"); else if ( $color == "red" ) print("Fire\n"); else if ($color == "yellow" ) print("Sun\n"); else print("I give up!\n");