Recall & Review
beginner
What does the
@for $i from 1 through 5 loop do in Sass?It loops from 1 to 5, including both 1 and 5. So, it runs 5 times with $i values 1, 2, 3, 4, and 5.
Click to reveal answer
beginner
What is the difference between
through and to in a Sass @for loop?through includes the last number in the loop, while to stops before the last number. For example, @for $i from 1 through 5 runs 5 times, but @for $i from 1 to 5 runs 4 times.Click to reveal answer
beginner
How would you write a Sass
@for loop that runs exactly 3 times with $i values 1, 2, and 3?Use
@for $i from 1 through 3 to include the number 3 in the loop.Click to reveal answer
intermediate
What happens if you use
@for $i from 1 to 1 in Sass?The loop does not run at all because
to excludes the last number, so it loops from 1 up to but not including 1.Click to reveal answer
beginner
Why might you choose
through over to in a Sass @for loop?Choose
through when you want to include the last number in your loop count, for example, when styling a fixed number of elements or steps.Click to reveal answer
What does
@for $i from 1 to 4 do in Sass?✗ Incorrect
to excludes the last number, so it loops from 1 up to but not including 4.Which keyword includes the last number in a Sass
@for loop?✗ Incorrect
through includes the last number in the loop.How many times will
@for $i from 1 through 3 run?✗ Incorrect
It runs 3 times with $i values 1, 2, and 3.
If you want to loop from 1 to 5 but exclude 5, which do you use?
✗ Incorrect
to excludes the last number, so it stops before 5.What happens if you write
@for $i from 1 to 1?✗ Incorrect
The loop does not run because
to excludes the last number and 1 to 1 means no iterations.Explain the difference between
through and to in a Sass @for loop.Think about whether the last number is counted or not.
You got /3 concepts.
Describe a situation where you would use
@for $i from 1 through 5 instead of @for $i from 1 to 5.When you want to style or create exactly 5 items.
You got /3 concepts.