Loops

Loops are extremely useful in any type of programming.
They make the computer do something over and over and over again, so you don't have to.
Suppose for some reason you need Maya to print out the numbers 1 through 100.

{
	int $i;
	for( $i = 1; $i <= 100; $i++ )
	{
		print $i;
	}
}


The stream of numbers that made wasn't very cool. Replace: print $i; with print ($i + "\n"); For more on that read about working with strings.
Here's how the loop works. The for loop takes three arguments. A start expression, an end condition, and an update-expression. for( $i = 1; $i <= 100; $i++ ) The start expression is executed once, when the computer first begins the loop. $i = 1; In this case it sets $i to equal 1; The end condition is checked for each time. As long as the end condition is true, the loop keeps going. $i <= 100; The update-expression is executed each time the loop completes. The ++ operator means "take the current value and add 1 to it." Now that loop was pretty useless. Here's how to use loops to cover some 3d space. { int $x; for ($x = 0; $x < 10; $x++) { polyCube -w .9 -h .9 -d .9; move $x 0 0; } } To add another dimension, just add another loop. They can be nested. { int $x; int $y; for ($x = 0; $x < 10; $x++) { for ($y = 0; $y < 10; $y++) { polyCube -w .9 -h .9 -d .9; move $x $y 0; } } } You can nest as many loops as you want, or the computer can handle. Each time the outside loop completes one loop, the inside loop does 10. Full 3d looks like: { int $x; int $y; int $z; for ( $x = 0; $x < 10; $x++ ) { for ( $y = 0; $y < 10; $y++ ) { for ( $z = 0; $z < 10; $z++ ) { polyCube -w .9 -h .9 -d .9; move $x $y $z; } } } } In case you're wondering why the lines are lined up the way they are, see this page on style.
There's a lot more to do with loops. I'll get to it a little later, or you can skip on to loops2 if you're impatient.