Yogesh Chauhan's Blog

How does while loop work in SCSS?

in SCSS on July 20, 2021

Similar posts:

for @each loop in SCSS

for loop in SCSS

SassScript has a rule @while that is used for writing a while loop with a code block.


@while {

SassScript @while loop works same as JavaScript while loop.

  • If the expression returns true then run the code block inside the curly brackets.
  • After the execution of the code block inside the loop, check again if the expression is true.
  • If not, do not then stop execution of the loop.
  • Keep executing the code block inside the brackets till the expression is true.


$min: 0;

@while $min < 5 {
    .p-#{$min*5} {
        padding: (5*$min) + px;

    $min: $min + 1;

The code above will compile into the following CSS code:

.p-0 {
	 padding: 0px;
 .p-5 {
	 padding: 5px;
 .p-10 {
	 padding: 10px;
 .p-15 {
	 padding: 15px;
 .p-20 {
	 padding: 20px;

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 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#Aug 15 Is PHP still good for back-end programming? #Aug 10 How to create a multisite network in WordPress? #Aug 3 How to create a circle that follows a cursor using JavaScript and CSS? #Aug 3 How to make a curtain slider using jQuery and CSS? #Aug 2 How to progressively load images and add a blurry placeholder? #Aug 1 How to create a placeholder loader (throbber) using CSS?
You might also like these
OOP, Class and Objects Strategies For Beginners (PHP)PHPWhy it’s not a good idea to create Number objects in JavaScript?JavaScriptResponsive Masonry Grid using CSS columns PropertyCSSHow to show confirmation alerts with OK and cancel buttons using Swift 5?SwiftHow to create a Star Ratings using CSS?CSSWhat are Null Sessions?MiscellaneousSome interesting HTML Input Attributes to rememberHTMLHow to scroll contents of HTML body horizontally and vertically using JavaScript?JavaScriptAvoid using new Array() in JavaScriptJavaScriptSQL GROUP BY StatementSQL/MySQLHow to create a Child Theme in WordPress?WordPressHow to use images instead of HTML radio buttons using CSS?CSS