HTML Diff
0 added 0 removed
Original 2026-01-01
Modified 2026-03-09
1 <h2>While loop</h2>
1 <h2>While loop</h2>
2 <h3>Syntax</h3>
2 <h3>Syntax</h3>
3 while (condition) { actions }<p>Actions will be executed again and again until the condition returns false.</p>
3 while (condition) { actions }<p>Actions will be executed again and again until the condition returns false.</p>
4 <h3>Accumulation of values in a loop</h3>
4 <h3>Accumulation of values in a loop</h3>
5 var sum = 0; var i = 0; while (i &lt;= 5) { sum += 1; i++; console.log(i); }<p>The program will log:</p>
5 var sum = 0; var i = 0; while (i &lt;= 5) { sum += 1; i++; console.log(i); }<p>The program will log:</p>
6 LOG: 1 (number) LOG: 2 (number) LOG: 3 (number) LOG: 4 (number) LOG: 5 (number) LOG: 6 (number) // Loop body code will not be executed, the condition will return false<h2>Calculating percentage of a number</h2>
6 LOG: 1 (number) LOG: 2 (number) LOG: 3 (number) LOG: 4 (number) LOG: 5 (number) LOG: 6 (number) // Loop body code will not be executed, the condition will return false<h2>Calculating percentage of a number</h2>
7 <p>The easiest way to find a percentage of the number is to divide the number by 100 and multiply by the percentage.</p>
7 <p>The easiest way to find a percentage of the number is to divide the number by 100 and multiply by the percentage.</p>
8 // Let’s calculate 2 percent of 100 1000 / 100 * 2 = 20; // Let’s calculate 7 percent of 1200 1200 / 100 * 7 = 84;<a>Continue</a>
8 // Let’s calculate 2 percent of 100 1000 / 100 * 2 = 20; // Let’s calculate 7 percent of 1200 1200 / 100 * 7 = 84;<a>Continue</a>