Search code examples
mel

MEL script do...while endless loop


I create an endless loop with this code:

int $a = 1;
int $b = 2;
int $c = 10;
do  {
        if(($a + $b) < $c){
            print ($a + $b);
            $a++;
            } 
    }
while($a < $c);

Do anyone see what I'm doing wrong?


Solution

  • This should work: I'm guessing the problem had to do with scope. So removed the brackets. https://knowledge.autodesk.com/support/maya/learn-explore/caas/sfdcarticles/sfdcarticles/How-MEL-handles-scope.html

    int $a = 1;
    int $b = 2;
    int $c = 10;
    
    do {
        if (($a + $b) < $c)
            print ($a + $b);
            $a++;
    }
    while ($a < $c);
    

    Alternative syntax:

    int $a = 1;
    int $b = 2;
    int $c = 10;
    
    for ($a; $a < $c; $a++)
    {
        if (($a + $b) < $c)
        {
            print ($a + $b);
        }
    }