Introduction to Loops

In the previous lesson, we learned how to store multiple data items in a single variable using arrays and how to manipulate arrays. In this lesson, we will discover how to repeat a part of the code based on a condition.

Repetition or iteration is an extremely important concept in programming, which we use in the form of loops.

We will show a few examples where loops are used.

Imagine you have an array of 500 students, and for each one, you have stored their age. Each year, we would need to update their ages. You can probably imagine how exhausting it would be to update the age of each student individually. Therefore, we can use a loop that goes through each student and updates their age.

Or in a game, if you have 60 FPS, it means the game code repeats 60 times per second. Every game is essentially one big loop that keeps repeating. In this case, it would be almost impossible to create a game without loops.

Now that we know why loops are important, we can move on to the next exercise and start using loops!

Instructions

When you are ready, proceed to the next exercise!

Start programming for free

By signing up, you agree to the Terms of Service and Privacy Policy.

Or sign up with:

1/9

Introduction to Loops | Start Coder