P
P
Pavel Pavel2019-01-17 02:41:31
Sass
Pavel Pavel, 2019-01-17 02:41:31

How to calculate the sum of all values ​​in a loop?

For example:

@for $i from 1 through 10
  $number: 121px * $i
    .box-#{$i}
      -width: $number

It will give 10 blocks with different widths. But how do you calculate the sum of all these widths?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey delphinpro, 2019-01-17
@PavelPav

Arithmetic progression, they should have been talking about it at school.
on scss:

$count: 10;
$baseWidth: 121px;

$sum: ($baseWidth + $baseWidth * $count) / 2 * $count;

result:

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question