Beep boop. Are you on a mobile device?

codeCampus is a desktop / tablet experience. Log back in on one of those devices and we can get coding!

Chapter 4
Doing Stuff Forever

Pssst...use your keyboard arrows to turn the page!

Arrow keys

Remember that loops are just a way for us to repeat code over and over again, without having to actually write all of that code over and over again.


Repeat loops are great for when we know exactly how many times we want our instructions to repeat. But if we don't know how many times it needs to repeat, we'll use the forever loop!

Just like its name says, the Forever Loop repeats any instructions that are put inside of it forever – or, until our project is stopped.


The awesome thing about the forever loop is that we don’t have to tell it how long to run for – it’ll just keep repeating instructions for as long as it has to! That could end up being tens, hundreds, or even BILLIONS of times.


Now, as programmers, we use forever loops because we don’t know how long people will be playing the games we make. They could play it for just five seconds, or they could play it for a hundred years straight!

The forever loop will make sure that no matter how long someone is playing our game, the game will keep doing the things it needs to do without stopping.


To recap, a forever loop is a type of loop that will repeat the instructions inside of it an infinite number of times.