Loops
Lesson 1 of 1
1. 1
Why write 100 lines of code when you can write 2? When we come across code we want to repeat, we can rely on loops. Loops give us the ability to repeat specified blocks of code as many times as w…
2. 2
When we know how many times we want a section of code to repeat, we often use a for loop. A for loop starts with the for keyword and is followed by a statement that defines a loop variable foll…
3. 3
Sometimes we want to count backwards, or count by 2s, or both! Using certain functions alongside or instead of the normal range operator (..) can enhance the iterative abilities of our for loops. T…
4. 4
Instead of using a range, we can use the structure of a collection as an iterator. A for loop will iterate through each of the collection’s elements with the loop variable holding the value of the …
5. 5
Unlike a list or a set, a map is a collection of entries. When using a map as a for loop iterator, we can iterate through each entry of the map or through just the keys, or just the values. When …
6. 6
When repeating code we may not have a range or defined collection to dictate the number of loops we need to execute. In this case, we can rely on a while loop which repeats code as long as a spe…
7. 7
A do..while loop is just like a while loop except the looping condition is checked at the end of the loop body. This is known as an exit-condition loop and means the code in the body will execute a…
8. 8
Loops inside loops, oh my! A nested loop represents one loop placed inside the body of another loop which results in a higher dimensions of iterations. This strategy is most often used when we’d li…
9. 9
The jump expressions, break and continue, are used to change the standard loop behavior by exiting a loop early or skipping a single repetition. The break expression is used to exit the loop at a…
10. 10
“How would we use jump expressions inside nested loops?” Good question! The answer is labeled jump expressions. By adding a label to the outer loop of nested loops, we can execute a jump expressi…

## What you'll create

Portfolio projects that showcase your new skills

## How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory