Problem 28. table1to10.js ( printing table of 1 to 10) Nested foloop is introduced

 /*Question

Print table of 1 to 10
*/

// Normal table of 1

let num = 1;

let i = 1; // initialization of while loop

while (i <= 10) {
console.log(num * i)

i++; // increment of while loop
}

TERMINAL:
Nobins-MacBook-Pro:STOC_MODULE 11SEPT 2022 nobinpunyo$ node table1to10.js 1 2 3 4 5 6 7 8 9 10 Nobins-MacBook-Pro:STOC_MODULE 11SEPT 2022 nobinpunyo$

// Table from 1 to 10


/*Question
Print table of 1 to 10
*/


for (let i = 1; i <= 10; i++) // 1) i=1

{

let num = i; // 1) num =1

// initialization of while loop
let j = 1; // 1) j=1 2) j=2 3) j=3

while (j <= 10) // 1) j<=10 2) j<=10 3) j<=10
{
console.log(num * j); //1) 1*1 = 1 2) 1*2 = 2 3)1*3 = 3

j++; // increment of while loop 1) now j++ = 2 , now j++ = 3 now continue this while
loop till j=10 and when j=10 we get out of the while loop and start forloop
for next iteration i++ i,e i=2 so num is also = 2 and continue the same
process till i=10

}


}

TERMINAL:
Nobins-MacBook-Pro:STOC_MODULE 11SEPT 2022 nobinpunyo$ node table1to10.js 1 2 3 4 5 6 7 8 9 10 2 4 6 8 10 12 14 16 18 20 3 6 9 12 15 18 21 24 27 30 4 8 12 16 20 24 28 32 36 40 5 10 15 20 25 30 35 40 45 50 6 12 18 24 30 36 42 48 54 60 7 14 21 28 35 42 49 56 63 70 8 16 24 32 40 48 56 64 72 80 9 18 27 36 45 54 63 72 81 90 10 20 30 40 50 60 70 80 90 100 Nobins-MacBook-Pro:STOC_MODULE 11SEPT 2022 nobinpunyo$


Comments

Popular posts from this blog

Problem 33. patter122333.js

Problem 38. diamond.js

Problem 16. chocolatebills.js