This site is a preview of the curriculum for our Summer 2018 bootcamp in Burlington, Vermont. As we continue our preparation, courses and lessons will appear and disappear; we will rename, rearrange, clarify, and obfuscate as needed... Please consider this a work in progress and keep checking in.

Learn to Code with JavaScript:

Loops

Slides

Loops

Computers are like robots. They are good at doing things over and over and over and over again.

A LOOP is when we ask a program to do something many times.

while

The simplest loop in JavaScript is while.

while (someCondition) {
someAction()
}

In English this reads, "While some condition is true, do some action".

while true

If you want something to keep going forever, set condition to true:

while (true) {
console.log("Hello")
}

This means "While true is true, say 'Hello'". Obviously true will always be true, so it goes forever.

To stop it, hold down the CONTROL key and press the C key.

This is called an infinite loop.

Note well! The lines between { and } are INDENTED. Indentation is very important to you and other humans. It lets our eyes follow the patterns and helps us quickly see what parts of the program go with each other.