在 Sass 中编写一个以 1 以外的值递增的循环 [英] Writing a loop that increments by a value other than 1 in Sass
本文介绍了在 Sass 中编写一个以 1 以外的值递增的循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 SASS 中,循环是这样写的:
In SASS, a loop is written like so:
@for $i from 1 through 100 {
//stuff
}
这将产生 1、2、3、4... 一直到 100.
This would yield 1, 2, 3, 4... all the way to 100.
如何让循环以两个单位为间隔进行?
How would you make the loop go in intervals of two units?
@for $i from 1 through 100 *step 2*{
//stuff
}
所以结果是 1, 3, 5, 7... 到 99
So the result is 1, 3, 5, 7... to 99
推荐答案
它不在文档中,因为它根本没有实现.您可以使用 @while
指令完成您想要做的事情.
It isn't in the documentation because it simply isn't implemented. What you want to do can be done with the @while
directive.
$i: 1;
@while $i < 100 {
// do stuff
$i: $i + 2;
}
这篇关于在 Sass 中编写一个以 1 以外的值递增的循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文