0
0
SASSmarkup~5 mins

@while loop usage in SASS - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the @while loop in Sass?
The @while loop in Sass repeats a block of styles as long as a condition is true. It helps automate repetitive CSS tasks.
Click to reveal answer
beginner
How do you write a basic @while loop in Sass?
You start with @while followed by a condition in parentheses, then curly braces with the styles inside. Example:<br>
$i: 1;<br>@while $i < 5 {<br>  .item-#{$i} {<br>    width: 10px * $i;<br>  }<br>  $i: $i + 1;<br>}
Click to reveal answer
beginner
Why must you update the loop variable inside a @while loop in Sass?
If you don’t update the loop variable, the condition stays true forever, causing an infinite loop. You must increase or change the variable to eventually stop the loop.
Click to reveal answer
beginner
What happens if the @while loop condition is false at the start?
The loop block does not run at all. Sass skips the styles inside the @while block because the condition is not met.
Click to reveal answer
beginner
Give a real-life example where @while loop in Sass can be useful.
When you want to create multiple classes with incremental styles, like buttons with increasing padding or grid columns with different widths, @while helps write less code and keep it consistent.
Click to reveal answer
What must you do inside a @while loop to avoid an infinite loop?
AUpdate the loop variable so the condition eventually becomes false
BUse <code>@break</code> outside the loop
CWrite the loop without any condition
DUse <code>@if</code> inside the loop
What does this Sass code do?<br>
$i: 1;<br>@while $i <= 3 {<br>  .box-#{$i} {<br>    width: 20px * $i;<br>  }<br>  $i: $i + 1;<br>}
ACreates three classes with widths 20px, 40px, and 60px
BCreates one class with width 20px
CCreates infinite classes
DDoes nothing because $i is not updated
If the condition in @while is false at the start, what happens?
AThe loop runs once
BThe loop runs infinitely
CThe loop block is skipped
DAn error occurs
Which of these is a common @while loop condition in Sass?
A$count == 10
B$count < 10
C$count > 10
D$count != 10
What is the main benefit of using @while loops in Sass?
ATo define variables
BTo create animations
CTo import other Sass files
DTo write repetitive CSS automatically
Explain how a @while loop works in Sass and why updating the loop variable is important.
Think about how a stop sign works in real life to end a repeated action.
You got /4 concepts.
    Describe a practical example where you would use a @while loop in Sass to simplify your CSS.
    Imagine making many buttons with different sizes or colors.
    You got /4 concepts.