HTML Diff
0 added 0 removed
Original 2026-01-01
Modified 2026-03-09
1 <h2>Loop for</h2>
1 <h2>Loop for</h2>
2 <h3>Syntax</h3>
2 <h3>Syntax</h3>
3 for (var i = 0; i &lt; 10; i++) { // repeated commands }<p>var i = 0; preparatory part, the initial value for the counter. Set with var, as an ordinary variable.</p>
3 for (var i = 0; i &lt; 10; i++) { // repeated commands }<p>var i = 0; preparatory part, the initial value for the counter. Set with var, as an ordinary variable.</p>
4 <p>i &lt; 10; checking part. If the condition returns true, the loop completes one more iteration, otherwise the loop stops.</p>
4 <p>i &lt; 10; checking part. If the condition returns true, the loop completes one more iteration, otherwise the loop stops.</p>
5 <p>i++ complementary part, launched at each iteration, after executing the code from the body of the loop. Changes counter value.</p>
5 <p>i++ complementary part, launched at each iteration, after executing the code from the body of the loop. Changes counter value.</p>
6 <h3>Accumulation of values in a loop:</h3>
6 <h3>Accumulation of values in a loop:</h3>
7 var sum = 0; for (var i = 1; i &lt;= 5; i++) { sum += 2; console.log(sum); }<p>The program will log:</p>
7 var sum = 0; for (var i = 1; i &lt;= 5; i++) { sum += 2; console.log(sum); }<p>The program will log:</p>
8 LOG: 2 (number) LOG: 4 (number) LOG: 6 (number) LOG: 8 (number) LOG: 10 (number)<h3>Checks in the loop body</h3>
8 LOG: 2 (number) LOG: 4 (number) LOG: 6 (number) LOG: 8 (number) LOG: 10 (number)<h3>Checks in the loop body</h3>
9 var sum = 0; for (var i = 1; i &lt;= 5; i++) { if (i &gt; 2) { sum += 1; } }<h2>Searching for an even number</h2>
9 var sum = 0; for (var i = 1; i &lt;= 5; i++) { if (i &gt; 2) { sum += 1; } }<h2>Searching for an even number</h2>
10 <p>The % operator or the “remainder in division” returns the remainder in division.</p>
10 <p>The % operator or the “remainder in division” returns the remainder in division.</p>
11 10 % 5; // Returns 0 12 % 5; // Returns 2 7 % 3; // Returns 1 5.5 % 2; // Returns 1.5<p>If the remainder in division of the number by 2 equals 0, the number is even, otherwise it is odd.</p>
11 10 % 5; // Returns 0 12 % 5; // Returns 2 7 % 3; // Returns 1 5.5 % 2; // Returns 1.5<p>If the remainder in division of the number by 2 equals 0, the number is even, otherwise it is odd.</p>
12 <a>Continue</a>
12 <a>Continue</a>