YogeshChauhan . com

How to create a for loop in SCSS (Sass)?

in SCSS on June 9, 2021

The for loop is created using a @for rule.


Syntax 1

@for <variable> from <expression> to <expression> { 

Syntax 2

@for <variable> from <expression> through <expression> { 

Both of the syntaxes above counts from one end (first expression) to the other end (second expression) and evaluates the block inside the loop for each single increment or decrement.

We use variable right after starting the for rule and that variable is assigned the number from the loop every time.

If you use @for rule with “to” then the final number is not included but if you use @for rule with “through” then the final number is included.

@for loop example with through

@for loop example with to


Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to add Read More Read Less Button using JavaScript? #4 How to uninstall Cocoapods from the Mac OS? #5 How to Use SQL MAX() Function with Dates? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

Jun 16 What are Stored Procedures for SQL Server? Jun 16 What are Class Constants in PHP? Jun 15 A short basic guide on states in React Jun 15 How to define constants in PHP? Jun 15 How to define visibility for a property in PHP? Jun 15 How to use @if and @else in SCSS?

You might also like these

10 Usability Blunders to AvoidUI/UXHow to get the full URL of current page in PHP?PHPHow to Make a Simple Module with a Form and Menu Link in Drupal 7.x?DrupalJavaScript: Methods for HTML DOM classList PropertyJavaScriptSequence generator (range) using JavaScript Array.from()JavaScriptHow to define constants in PHP?PHPHow to set the permissions on all files and folders in Mac?MiscLearn to make a responsive gallery using CSS Grid and without media queriesCSSConditional operator in JavaScript (aka ternary operator)JavaScriptHow to convert datetime to date format in JavaScript?JavaScriptWordPress: How to find all posts from a custom post type with multiple custom fields values?WordPressHow to get category name using post id in WordPress?WordPress