+ 14

DIFFERENCE OF SEMICOLON ( ; ) HOW??

for(var i=1;i<=10;i++){ for(var k=1;k<=10;k++) document.write(i," * ",k," = ",k*i,"<br/>") } // output table from 1 to 10 But when we apply semi colon ( ; ) Then it's totally changed for(var i=1;i<=10;i++){ for(var k=1;k<=10;k++); document.write(i," * ",k," = ",k*i,"<br/>") } //output table of 11 https://code.sololearn.com/WCiuo1jbU1r9/?ref=app

20th Apr 2019, 8:21 PM
Rishabh Singh
Rishabh Singh - avatar
1 Odpowiedź
+ 10
When you write: for (var k = 1; k <= 10; k++); Thats just a for loop whitout a body So it will run just as normal incrementing the variable k by 1 on each iteration Then when k == 11 The k <= 10 part of loop is not satisfied so it will end and move on to the next statement: document.write(... k * i...) // 11 times every number from 1 to 10
20th Apr 2019, 8:40 PM
Mind To Machine 💻🕆
Mind To Machine 💻🕆 - avatar