Class: MEL Programming Basics
Instructor: Mike Harris email
Class: 3
Date: March 7, 2006

MEL Programming Basics

        initialize condition;
        while ( conditionStatement )
        {
            block of code;
            increment/decrement condition;
        }
        for ( startValue; valueTest; incrementValue )
        {
            block of code;
        }
        initialize arrayList;
        for ( currentElement in arrayList )
        {
            block of code;
        }
        int $x = 1;
        while ( $x > 0 )    // $x will always be greater than 0, causing an infinite loop!
        {
            print ("Keep looping...\n");
            $x++;
        }
        string $selected[] = `ls -selection`;
        for ( $current in $selected )
        {
            string $relatives[] = `listRelatives -shapes $current`;
            if ( $relatives[0] != "" )
            {
                for ( $object in $relatives )
                {
                    print ( "The shape node for " + $current + " is: " + $object + "\n" );
                }
            }
            else
                print ( $current + " is a transform node.\n" );
        }

        string $sceneList[] = `ls -selection`;
        int $i = 1;
        print ( "This is the While Loop example.\n" );
        while ( $i <= size( $sceneList ))
        {
            print ( "\tItem " + $i + " is: " + $sceneList[$i - 1] + "\n" );
            $i++;
        }
        print ( "That is the end of the selection list." );

        string $sceneList[] = `ls -selection`;
        print ( "This is the For Loop example.\n" );
        for ( $i = 1; $i <= size( $sceneList ); $i++)
        {
            print ( "\tItem " + $i + " is: " + $sceneList[$i - 1] + "\n" );
        }
        print ( "That is the end of the selection list." );

        string $sceneList[] = `ls -selection`;
        int $i = 1;
        print ( "This is the For-in Loop example.\n" );
        for ( $current in $sceneList )
        {
            print ( "\tItem " + $i + " is: " + $current + "\n" );
            $i++;
        }
        print ( "That is the end of the selection list." );