0
0
SASSmarkup~5 mins

@for loop (through vs to) in SASS - Quick Revision & Key Differences

Choose your learning style9 modes available
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?
ALoops with $i values 1, 2, 3, 4
BLoops with $i values 2, 3, 4
CLoops with $i values 1, 2, 3
DLoops with $i values 1, 2, 3, 4, 5
Which keyword includes the last number in a Sass @for loop?
Aend
Bto
Cuntil
Dthrough
How many times will @for $i from 1 through 3 run?
A3 times
B2 times
C4 times
D1 time
If you want to loop from 1 to 5 but exclude 5, which do you use?
Athrough
Bto
Cuntil
Dfrom
What happens if you write @for $i from 1 to 1?
ADoes not run
BRuns twice with $i = 1, 2
CRuns once with $i = 1
DRuns infinitely
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.