A Useable Procedure

Here we'll take the 3d checker script and turn it into a useable procedure.
Here is the script from my example, please feel free to use your own.
You'll learn more by adapting the examples here to fit your script than from copying mine.
The basic script, in procedure format:

global proc djnCheckerCube ()
{
	// three dimensional checker board
	int $x;
	int $modX;
	int $y;
	int $modY;
	int $z;
	int $modZ;
	for ($x = 0; $x < 10; $x++)
	{
		$modX = $x % 2;
		for ($y = 0; $y < 10; $y++)
		{
			// if x is even, invert y
			if ($modX)
			{
				$modY = $y % 2;
			}else{
				$modY = 1 - ($y % 2);
			}
			for ($z = 0; $z < 10; $z++)
			{
				$modZ = $z % 2;
				// place a cube on the odds
				if ($modY && $modZ)
				{
					polyCube;
					move $x $y $z;
				}
				// place a cube on the evens
				if (!$modY && !$modZ)
				{
					polyCube;
					move $x $y $z;
				}
			}
		}
	}
}

Notice how I put my initials in front of the procedure name?  Its a good idea to personalize
all your procedures in some way, to avoid conflicting with any of Maya's built in procedures.
I ran into this one time when I used a procedure called "createButtons" to place some buttons in a window.
It turned out the Hypershade uses a procedure with the exact same name, so after I ran my script the 
Hypershade would no longer open.

The first thing to think about when turning a straight-forward script like the 3d checker script into
a procedure is if the whole script should be one procedure or if it should be broken up.
In this case, the whole action is one sequence so it should be one proc.
Next think about what arguments it should take.
Let's give it three, for the number of cubes in each dimension:

global proc djnCheckerCube (int $xDim, int $yDim, int $zDim)
{
	// three dimensional checker board
	int $x;
	int $modX;
	int $y;
	int $modY;
	int $z;
	int $modZ;
	for ($x = 0; $x < $xDim; $x++)
	{
		$modX = $x % 2;
		for ($y = 0; $y < $yDim; $y++)
		{
			// if x is even, invert y
			if ($modX)
			{
				$modY = $y % 2;
			}else{
				$modY = 1 - ($y % 2);
			}
			for ($z = 0; $z < $zDim; $z++)
			{
				$modZ = $z % 2;
				// place a cube on the odds
				if ($modY && $modZ)
				{
					polyCube;
					move $x $y $z;
				}
				// place a cube on the evens
				if (!$modY && !$modZ)
				{
					polyCube;
					move $x $y $z;
				}
			}
		}
	}
}


Easy enough, right?
We'll switch over to interface building, and create a basic window for this script.
Then we'll add some more advanced features to this script.
As a script gets more complex it eventually becomes necessary to have an interface,
even before its ready for  "release".  It can really speed up debugging as it puts
you in the mind of the user, who may try to do things you wouldn't consider doing.