2018-09-01 22:35:20 +02:00
|
|
|
---
|
|
|
|
title: "@for"
|
|
|
|
---
|
|
|
|
|
|
|
|
The `@for` rule, written
|
|
|
|
`@for <variable> from <expression> to <expression> { ... }` or
|
|
|
|
`@for <variable> from <expression> through <expression> { ... }`, counts up or
|
|
|
|
down from one number (the result of the first [expression][]) 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.
|
|
|
|
|
2019-01-09 23:14:29 +01:00
|
|
|
[expression]: ../../syntax/structure#expressions
|
2018-09-01 22:35:20 +02:00
|
|
|
|
|
|
|
<% example do %>
|
2018-10-23 22:42:40 +02:00
|
|
|
$base-color: #036;
|
2018-09-01 22:35:20 +02:00
|
|
|
|
2018-10-23 22:42:40 +02:00
|
|
|
@for $i from 1 through 3 {
|
|
|
|
ul:nth-child(3n + #{$i}) {
|
|
|
|
background-color: lighten($base-color, $i * 5%);
|
|
|
|
}
|
2018-09-01 22:35:20 +02:00
|
|
|
}
|
2018-10-23 22:42:40 +02:00
|
|
|
===
|
|
|
|
$base-color: #036
|
2018-09-01 22:35:20 +02:00
|
|
|
|
2018-10-23 22:42:40 +02:00
|
|
|
@for $i from 1 through 3
|
|
|
|
ul:nth-child(3n + #{$i})
|
|
|
|
background-color: lighten($base-color, $i * 5%)
|
2018-09-01 22:35:20 +02:00
|
|
|
<% end %>
|