Mel - Maya Embedded Language


Loops and If Blocks - switch

if then else
for in
do while


The switch statement can be used to shorten a long list of if statements.
int $random= rand(0,10);
case 0:
     print "\n The number is 0";
case 1:
     print "\n The number is 1";
case 2:
     print "\n The number is 2";
case 3:
     print "\n The number is 3";
case 4:
     print "\n The number is 4";
     print "\n I give up! Game over! The number is greater than 4";
     print ("\n Just kidding. The number is actually " + $random);
If you want more than one case to execute, omit the break. All cases that are true will execute. The switch will not exit until it reaches the end of the cases or encounters another break.