Mel - Maya Embedded Language

switch

The switch statement can be used to shorten a would be long list of if statements.
int $random= rand(0,10);
switch($random)
{
case 0:
	print "\ndude case is 0";
	break;
case 1:
	print "\ndude case is 1";
	break;
case 2:
	print "\ndude case is 2";
	break;
case 3:
	print "\ndude case is 3";
	break;
case 4:
	print "\ndude case is 4";
	break;
default:
	print "\ndude I give up! Game over! case is greater than 4";
	print ("\nha ha dude... Just kidding. Case is actually " + $random);
}

If you want more than one case to execute if a given case is true simply omit its break. This will not stop the case from executing the cases which follow. The switch will not exit until it reaches the end of the cases or encounters another break.