Loops are a way to do an action over and over again, within constraints that you set.
It is a good way to change a bunch of things at once!
We are going to learn a second type of loop that is different from a while loop: afor loop.

parts of a for loop

Use the buttons below to add body segments to the BitbyBotapillar. Then, use the second set of buttons to make changes to all the body segments.
Usually, a loop runs very quickly - so quickly you don't see each change individually!
Choose "Loop Slowly" if you would like to see it run slowly.

Add body segments:

bodySegments.length = 1


Loop Speed:


I want to...

Bit By Botterpillar Head
1
// Finds all Bit-by-Botapillar body segments and stores them in a variable
let bodySegments = document.getElementById("bodySegment");

// Loop function
function caterpillarLoop() {
 for (let i = 0; i < bodySegments.length; i++) {
  //

 }
};

// Calls the function
caterpillarLoop();