2023-05-30 12:12:01 +02:00
|
|
|
---
|
|
|
|
title: "@for"
|
|
|
|
introduction: >
|
2023-05-30 22:27:01 +02:00
|
|
|
The `@for` rule, written `@for <variable> from <expression> to <expression> {
|
|
|
|
... }` or `@for <variable> from <expression> through <expression> { ... }`,
|
2023-05-30 12:12:01 +02:00
|
|
|
counts up or down from one number (the result of the first
|
2023-05-30 22:27:01 +02:00
|
|
|
[expression](/documentation/syntax/structure#expressions)) to another (the
|
|
|
|
result of the second) and evaluates a block for each number in between. Each
|
|
|
|
number along the way is assigned to the given variable name. If `to` is used,
|
|
|
|
the final number is excluded; if `through` is used, it's included.
|
2023-05-30 12:12:01 +02:00
|
|
|
---
|
|
|
|
|
|
|
|
{% codeExample 'for' %}
|
2023-05-30 23:23:34 +02:00
|
|
|
$base-color: #036;
|
2023-05-30 12:12:01 +02:00
|
|
|
|
2023-05-30 23:23:34 +02:00
|
|
|
@for $i from 1 through 3 {
|
|
|
|
ul:nth-child(3n + #{$i}) {
|
|
|
|
background-color: lighten($base-color, $i * 5%);
|
|
|
|
}
|
2023-05-30 12:12:01 +02:00
|
|
|
}
|
2023-05-30 23:23:34 +02:00
|
|
|
===
|
|
|
|
$base-color: #036
|
2023-05-30 12:12:01 +02:00
|
|
|
|
2023-05-30 23:23:34 +02:00
|
|
|
@for $i from 1 through 3
|
|
|
|
ul:nth-child(3n + #{$i})
|
|
|
|
background-color: lighten($base-color, $i * 5%)
|
2023-05-30 12:12:01 +02:00
|
|
|
{% endcodeExample %}
|