Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing a loop that increments by a value other than 1 in Sass

Tags:

sass

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

like image 499
danivicario Avatar asked Sep 14 '13 13:09

danivicario


People also ask

Can you increment by 2 in a for loop?

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.

How do you add increments to a while loop?

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 .

How do I create a loop in sass?

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.

What is increment value in for loop?

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()


1 Answers

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; } 
like image 123
Bart Avatar answered Sep 21 '22 02:09

Bart