@for $var from <start> through <end>
$var: 它代表了變數的名稱如 $i.
<start> 和 <end>: 這些SassScript表示式將返回整數。如果<start>大於 <end>則計數器變數遞減,當<start>比小 <end>計數器變數會增加。
<html>
<head><meta charset="utf-8"> <title>Control Directives & Expressions</title>
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
<p class="p1">This is first line.</p>
<p class="p2">This is second line.</p>
<p class="p3">This is third line.</p>
<p class="p4">This is fourth line.</p>
</body>
</html>
@for $i from 1 through 4 { .p#{$i} { padding-left : $i * 10px; } }
sass --watch C:\Ruby22-x64\style.scss:style.css
.p1 { padding-left: 10px; } .p2 { padding-left: 20px; } .p3 { padding-left: 30px; } .p4 { padding-left: 40px; }