In SASS, a loop is written like so:
@for $i from 1 through 100 { //stuff }
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 }
So the result is 1, 3, 5, 7... to 99
A for loop doesn't increment anything. Your code used in the for statement does. It's entirely up to you how/if/where/when you want to modify i or any other variable for that matter.
First off, you will have to declare the index variable before the while loop. If you declare it inside, it will be a new variable each time it iterates. When that is done, you will need to increment the variable for each iteration, this can be done by either $i++ or $i+=1 .
We start with the @for rule, followed by the counter variable. Then we use the from keyword and the number to start looping from. Finally we use the through keyword and specify the number that we want to loop to, followed by a code block.
Increment is an expression that determines how the loop control variable is incremented each time the loop repeats successfully (that is, each time condition is evaluated to be true). Example. // this program uses the for loop to print the numbers from 1 through 100. #include <iostream.h> main()
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; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With