0 added
0 removed
Original
2026-01-01
Modified
2026-03-09
1
<p>Now we’ll print the pages in reverse order.</p>
1
<p>Now we’ll print the pages in reverse order.</p>
2
<p>The mode will be called 'reverse', you need to add a condition and a separate loop.</p>
2
<p>The mode will be called 'reverse', you need to add a condition and a separate loop.</p>
3
<p>How to write loops for similar conditions: “Add a loop that decreases the value of the variable i from 10 to 1 inclusively. Decrease the value of i by one at each iteration”? As usual, we will look into it step-by-step.</p>
3
<p>How to write loops for similar conditions: “Add a loop that decreases the value of the variable i from 10 to 1 inclusively. Decrease the value of i by one at each iteration”? As usual, we will look into it step-by-step.</p>
4
<p>”…a loop that decreases<strong>the value of variable i from 10</strong>up to 1 inclusively.” The counter here is i, and its starting value is 10. Writing it down.</p>
4
<p>”…a loop that decreases<strong>the value of variable i from 10</strong>up to 1 inclusively.” The counter here is i, and its starting value is 10. Writing it down.</p>
5
for (<b>var i = 10;</b>) { … }<p>”…a loop that decreases the value of the variable i <strong>from 10 to 1 inclusively</strong>.” This means that the loop will complete its work when i becomes equal to 0. For i = 1, the loop will execute the next iteration. Since the starting value of the counter is 10 and it will decrease to 1 inclusively, the “more or equal to” sign will work for us. We will compare with 1 since this is the value after which the loop should stop.</p>
5
for (<b>var i = 10;</b>) { … }<p>”…a loop that decreases the value of the variable i <strong>from 10 to 1 inclusively</strong>.” This means that the loop will complete its work when i becomes equal to 0. For i = 1, the loop will execute the next iteration. Since the starting value of the counter is 10 and it will decrease to 1 inclusively, the “more or equal to” sign will work for us. We will compare with 1 since this is the value after which the loop should stop.</p>
6
for (var i = 10;<b>i >= 1;</b>) { … }<p>Note that the condition can also be written slightly differently. If we need to take into account the value 1, but end the loop with a value less than 1, we can use the “more than” sign. We should only compare it with 0. Then one will be used precisely as the counter value, and for 0, the loop will end its work.</p>
6
for (var i = 10;<b>i >= 1;</b>) { … }<p>Note that the condition can also be written slightly differently. If we need to take into account the value 1, but end the loop with a value less than 1, we can use the “more than” sign. We should only compare it with 0. Then one will be used precisely as the counter value, and for 0, the loop will end its work.</p>
7
for (var i = 10;<b>i > 0;</b>) { … }<p>There are two options to write a condition in such cases, and both are true. You can use any.</p>
7
for (var i = 10;<b>i > 0;</b>) { … }<p>There are two options to write a condition in such cases, and both are true. You can use any.</p>
8
<p>“Decrease the value of i by one at each iteration.” Here we have the value change by one that we are used to. Only now we do not increase the value of the counter, but decrease it, and that’s why we use a decrement.</p>
8
<p>“Decrease the value of i by one at each iteration.” Here we have the value change by one that we are used to. Only now we do not increase the value of the counter, but decrease it, and that’s why we use a decrement.</p>
9
for (var i = 10; i > 0;<b>i--</b>) { … }<p>Back to the printer. In this mode, we will count the pages in reverse order and wait for the last page to print, in our case the first one, since we count from the end. We already had the page counter, that’s why we will use the reversePage since we count the pages in reverse order.</p>
9
for (var i = 10; i > 0;<b>i--</b>) { … }<p>Back to the printer. In this mode, we will count the pages in reverse order and wait for the last page to print, in our case the first one, since we count from the end. We already had the page counter, that’s why we will use the reversePage since we count the pages in reverse order.</p>