Mel - Maya Embedded Language

<HOME>   <PREVIOUS>   <NEXT>

Loops and If Blocks - do while loop

if then else
for
for in
while
do while
switch

do while

The do-while loop runs a command while the test condition is true
A do-while loop mainly consists of:

do
{
     do something;
}
while (test condition);


string $myArray [ ] = {"one","two","three","four"};
int $i =0;
do
{
     if ($myArray[$i] == "one")
          print ("\n"+$myArray[$i] + " dead roach!");
     else
          print ("\n"+$myArray[$i] + " dead roaches!");
     $i++; //do not forget this or Maya will get stuck in an infinite loop
}
while ( $i < size($myArray));

Exercise: Create a sphere then duplicate it, then move it by 1.5 along the X.
Use a do while loop to duplicate it using the smartTransform flag. Exit the loop when the X position exceeds 20.