2018-10-12 15:37:13 -04:00
|
|
|
---
|
|
|
|
|
title: Apply a Style Until a Condition is Met with @while
|
|
|
|
|
---
|
2019-02-13 03:02:07 +05:30
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
# Apply a Style Until a Condition is Met with @while
|
2018-10-12 15:37:13 -04:00
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
---
|
|
|
|
|
## Problem Explanation
|
2019-02-13 03:02:07 +05:30
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
This program is very simple, the trick is to remember how while looping works.
|
2019-02-13 03:02:07 +05:30
|
|
|
|
|
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
---
|
|
|
|
|
## Hints
|
2019-02-13 03:02:07 +05:30
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
### Hint 1
|
2019-02-13 03:02:07 +05:30
|
|
|
|
|
|
|
|
* **Make sure your zoom settings are at `100%` or `default` otherwise tests sometimes fail. **
|
|
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
### Hint 2
|
2019-02-13 03:02:07 +05:30
|
|
|
|
|
|
|
|
* You will initialise the loop first with x as: `$x: 1`
|
|
|
|
|
|
|
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
### Hint 3
|
2019-02-13 03:02:07 +05:30
|
|
|
|
|
|
|
|
* See the example for `@while` syntax, `@while $x < 11`
|
|
|
|
|
|
|
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
### Hint 4
|
2019-02-13 03:02:07 +05:30
|
|
|
|
|
|
|
|
* to set class properties inside a loop we reference them enclosed by #{}, hence ere it will become: `.text-#{$x}`
|
|
|
|
|
|
|
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
---
|
|
|
|
|
## Solutions
|
2019-02-13 03:02:07 +05:30
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
<details><summary>Solution 1 (Click to Show/Hide)</summary>
|
2019-02-13 03:02:07 +05:30
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
```scss
|
2019-02-13 03:02:07 +05:30
|
|
|
$x: 1;
|
|
|
|
|
@while $x < 11 {
|
|
|
|
|
.text-#{$x} {
|
|
|
|
|
font-size: 5px * $x;
|
|
|
|
|
}
|
|
|
|
|
$x: $x + 1;
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### Relevant Links
|
|
|
|
|
|
|
|
|
|
* <a href='https://sass-lang.com/documentation/file.SASS_REFERENCE.html#interpolation_' target='_blank' rel='nofollow'>Interpolation</a>
|
|
|
|
|
* <a href='https://sass-lang.com/documentation/file.SASS_REFERENCE.html#variables_' target='_blank' rel='nofollow'>Variables</a>
|
|
|
|
|
* <a href='https://sass-lang.com/documentation/file.SASS_REFERENCE.html#while' target='_blank' rel='nofollow'>while loops</a>
|
|
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
</details>
|