/

HTML / CSS / JavaScript Tutorial

JavaScript Statement: for

[this page | pdf | back links]

In JavaScript, the for statement identifies a block of statements that are to be executed whilst a condition is true (and a break or to some extent a continue statement have not been triggered).

 

For example, statements such as:

 

     var sumi = 0;

     var i;

     for (i = 1; i <= 5; i++) {sumi = sumi + i}

 

will loop through from i=1 to i=5 and calculate the sum (i.e. 1+2+3+4+5 = 15)

 


NAVIGATION LINKS
Contents | Prev | Next | JavaScript Reserved Words


Desktop view | Switch to Mobile