Skip to the content.

Looping code, references

Notes about the most interesting parts

1. Draw 100 random circles or squares:

2. An example where the standard for loop could be preferred over the for..of or for..in loops.

3. Exiting loops with break. If you want to exit a loop before all the iterations have been completed, you can use the break statement. The break statement will immediately exit the loop (as it is when we use it with a switch statement) and make the browser move on to any code that follows it.

4. Accomplish the same ask as in <3> but by using the .find() method.

5. Skipping iterations with continue. The continue statement works in a similar manner to break, but instead of breaking out of the loop entirely, it skips to the next iteration of the loop.

6. Achieve the same result as in <2>, but by using while and do..while loops.

Exercises

Exercise 1. Create list items:

Exercise 2. Phone book:

Exercise 3. …: