HTML Diff
0 added 0 removed
Original 2026-01-01
Modified 2026-03-09
1 <p>All printing modes are implemented.</p>
1 <p>All printing modes are implemented.</p>
2 <p>It’s time to write a single program that, depending on the set mode, will print the pages as we need them to be printed: multiple copies of one page, all pages of the document in direct and reverse order, only even or only odd pages.</p>
2 <p>It’s time to write a single program that, depending on the set mode, will print the pages as we need them to be printed: multiple copies of one page, all pages of the document in direct and reverse order, only even or only odd pages.</p>
3 <p>Let’s start with the page copying mode and gradually add other modes. The name of the mode will be stored in the variable mode.</p>
3 <p>Let’s start with the page copying mode and gradually add other modes. The name of the mode will be stored in the variable mode.</p>
4 <p>Of course, we will definitely need a loop here. Let’s look at an example to see how this formulation translates into the code: “Add a loop that increases the variable i from zero to 10 inclusive. Value i must increase by one after each iteration”.</p>
4 <p>Of course, we will definitely need a loop here. Let’s look at an example to see how this formulation translates into the code: “Add a loop that increases the variable i from zero to 10 inclusive. Value i must increase by one after each iteration”.</p>
5 <p>It is better to look at this task step-by-step. “Add a loop that<strong>increases i from zero</strong>to 10 inclusively.” It turns out that the variable that will change its value in the course of the loop will be i. Hence, this is the counter variable. Its value will change from 0 and further. That is, the starting value of the counter is 0. That’s how we should write it:</p>
5 <p>It is better to look at this task step-by-step. “Add a loop that<strong>increases i from zero</strong>to 10 inclusively.” It turns out that the variable that will change its value in the course of the loop will be i. Hence, this is the counter variable. Its value will change from 0 and further. That is, the starting value of the counter is 0. That’s how we should write it:</p>
6 for (<b>var i = 0;</b>) { … }<p>Note that we use var to declare the counter. This is the same variable as any other, and you need to declare it with var.</p>
6 for (<b>var i = 0;</b>) { … }<p>Note that we use var to declare the counter. This is the same variable as any other, and you need to declare it with var.</p>
7 <p>Let’s continue. “…increases the variable i from zero<strong>to 10 inclusively</strong>”. Hence, the value of the counter (variable i) will grow to 10. Since it says “up to 10 inclusively”, the last value of i, with which the loop will be executed, will be 10. For this value to get into the variable i and for the loop to be executed, use the sign &lt;=.</p>
7 <p>Let’s continue. “…increases the variable i from zero<strong>to 10 inclusively</strong>”. Hence, the value of the counter (variable i) will grow to 10. Since it says “up to 10 inclusively”, the last value of i, with which the loop will be executed, will be 10. For this value to get into the variable i and for the loop to be executed, use the sign &lt;=.</p>
8 for (var i = 0;<b>i &lt;= 10;</b>) { … }<p>“Value i must increase by one after each iteration”. Hence, we must add one to i after each iteration of the loop. We will use the increment.</p>
8 for (var i = 0;<b>i &lt;= 10;</b>) { … }<p>“Value i must increase by one after each iteration”. Hence, we must add one to i after each iteration of the loop. We will use the increment.</p>
9 for (var i = 0; i &lt;= 10;<b>i++</b>) { … }<p>In the example, we used the standard name i for the loop counter. For page copies, we will count how many copies have already been made and compare this number with the required number. That is, we will increase the number of copies. Therefore, the name copies will work for the counter here.</p>
9 for (var i = 0; i &lt;= 10;<b>i++</b>) { … }<p>In the example, we used the standard name i for the loop counter. For page copies, we will count how many copies have already been made and compare this number with the required number. That is, we will increase the number of copies. Therefore, the name copies will work for the counter here.</p>