+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

4/20/2019 8:21:29 PM

Rishabh

1 Answer

New Answer

+9

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