Looping Statements:

WHILE:

while ($a < 10) {
     print ($a + "\n");
}
 
D0 WHILE:
                 
do {
     print ($a + "\n");
} while ($a < 10);


FOR:

int $i;
for ($i = 1; $i <= 10; $i++) {
     print ($i + "\n");
}

FOR - IN  -  good for iterating through the current selection list:
     
for ($item in `ls -sl`) {
     print ($item + "\n");
}


Example FOR loop:

// example creates randomly placed spheres and adds dynamics
// clear scene before running
int $count = 10;
polyPlane;
scale -r 100 100 100 ;
rotate -r -os 0 0 -4 ;
rigidBody -passive ;
select -cl ;
gravity ;

int $i;
for ($i = 1; $i <= $count ; $i++) {
    polySphere ;
    move -r (rand(-40,40)) (rand(10,30)) (rand(-40,40));
    rigidBody -active -b 1.5;
    connectDynamic -f gravityField1 ("pSphere" + $i);
}