Class: MEL Programming Basics
Instructor: Mike Harris email
Class: 4
Date: March 9, 2006

MEL Programming Basics

                        // if condition //
                        if ( condition is true )
                                do something;

                        // if-else condition //
                        if ( first condition is true )
                                do something;
                        else
                                do something else;

                        // if-else if-else condition //
                        if ( first condition is true )
                                do something;
                        else if ( second condition is true )      // Multiple else if tests are optional and valid
                                do something else;
                        else if ( third condition is true )
                                do something else;
                        else if ( fourth condition is true )
                                do something else;
                        else
                                do something else;

                        switch (controlValue )
                        {
                            case value1:
                                statement;
                                break;
                            case value2:
                                statement;
                                break;
                            case value3:
                                statement;
                                break;
                            default:
                                statement;
                        }
                                                                                    // Global scope!
                                grandparent level
                                {                                                   // start gransparent scope
                                        parent level
                                        {                                           // start parent scope
                                                child1 level
                                                {                                   // start child1 scope

                                                }                                   // end child1 scope
                                                child2 level
                                                {                                   // start child2 scope

                                                }                                   // end child2 scope
                                        }                                           // end parent scope
                                }                                                   // end gransparent scope

                         for ( $i = 0; $i < 10; $i++ )
                         {
                                string $badscope = "Hello World!";
                                print ( "This is pass number: " + $i + " through the loop\n" );
                        }
                        print ( $badScope );   // This will give you an error because Maya no longer sees the variable $badScope
                        string $goodScope = "Hello World!";
                        for ( $i = 0; $i < 10; $i++ )
                        {
                                print ( $goodScope + "\n" );
                                print ( "This is pass number " + $i + " through the loop.\n" );
                        }
                        print ( $goodScope );   // Because the variable was declared outside the curly braces of the loop, Maya sees it both inside and outside of the nested loop
                        proc procName( arguments )   // arguments are optional
                        {
                                // Tasks to perform...
                        }
                        proc add2Numbers( float $numA, float $numB )
                        {
                                float $total = ( $numA + $numB );
                                print ( "The sum of " + $numA + " and " + $numB + " is: " + $total + "\n" );
                        }

                        add2Numbers( 3.5, 25.63 );