1. Java Script Module 2. World Wide Web (WWW) 3. Web Terms 4. NEED FOR SCRIPT 5. Introduction to Internet Programming 6. CLIENT SIDE and SERVER SIDE Scripting 7. Different Scripting Languages 8. Introduction to JavaScript 9. JavaScript and Security 10. How to Enable JavaScript 11. Advantages of Java Script 12. Limitations with JavaScript 13. Difference between JavaScript and JAVA 14. Difference between JavaScript and VBScript 15. JavaScript Development Tools 16. JavaScript Programming Techniques 17. JavaScript terms 18. Starting with JavaScript Programming step by step 19. Time to start JavaScript Programming 20. JavaScript Variables 21. JavaScript RESERVED WORDS 22. JavaScript Data Type 23. NUMBER DATA TYPE 24. BOOLEAN DATA TYPE 25. STRING DATA TYPE 26. NULL DATA TYPE 27. JavaScript Undefined DATA TYPE 28. JavaScript Operators 29. JavaScript Arithmetic Operators 30. JavaScript Logical Operators 31. JavaScript Comparison Operators 32. JavaScript String Operators 33. Bit Manipulation Operators 34. JavaScript Assignment Operators 35. JavaScript Conditional Operator 36. Conversion between JavaScript Data Types 37. Alert JavaScript function 38. confirm JavaScript function 39. prompt JavaScript function 40. JavaScript Statements 41. Single line & Multi-line Comments 42. JavaScrip If Statement 43. JavaScript if..else Statements 44. JavaScript If…else..if statement. 45. JavaScript For Statement 46. JavaScript Statement: 47. JavaScript While Statement 48. JavaScript do while Statement: 49. JavaScript break and continue statement 50. JavaScript switch Statement: 51. JavaScript function() 52. JavaScript function with a Return Value 53. JavaScript with Statement 54. try, catch, and throw Statements 55. JavaScript ARRAY 56. JavaScript array of different data types 57. JavaScript ARRAY and Bubble sorting Program 58. JavaScript Array Methods 59. concate() method 60. every() method 61. filter() method 62. forEach() method 63. indexOf() method 64. Join() method 65. lastIndexOf() method 66. map() method 67. reduce() method 68. reduceRight() method 69. reverse() method 70. some() method 71. toSource() method 72. toString() method 73. pop() method 74. push() method 75. shift () method 76. slice () method 77. splice () method 78. sort() method 79. unshift() method 80. EVENT handling with JavaScript 81. onblur JavaScript Event 82. onchange JavaScript Event 83. onclick JavaScript Event 84. onDblClick JavaScript Event 85. onfocus JavaScript Event 86. onkeydown JavaScript Event 87. onkeyup JavaScript Event 88. Onkeypress JavaScript Event 89. onLoad JavaScript Event 90. onMousedown JavaScript Event 91. onMouseup JavaScript Event 92. Onmouseover JavaScript Event 93. onmouseout JavaScript Event 94. onMouseMove JavaScript Event 95. onReset JavaScript Event 96. onsubmit JavaScript Event 97. onUnload JavaScript Event 98. The Screen Object 99. JavaScript Interview Part1 100. JavaScript Interview Part2 101. JavaScript Interview Part3 102. JavaScript Interview Part4 103. JavaScript Interview Part5 104. JavaScript Interview Part6 105. JavaScript Interview Part7 106. JavaScript Interview Part8 107. JavaScript Interview Part9 108. JavaScript Interview Part10
Pr.Pg Next Pg

For Statement OF JavaScript tutorials

  • This statement is used to perform multiple tasks of calculations and processing. It executes statements for more than one time in loop till result of the condition is true.

  • It is an entry controlled loop.

  • The for statement, first part initializes the loop. Initilization is executed only once. Here one or more variables can be initialized.

  • The Second part tests the condition, if result of the condition is true then it enters the loop part, it comes out of loop when result of the condition comes out to be false.

  • The third part is used for increment or decrement. More then one expressions can be used in increment/decrement.

  • Three expressions in for..loop are separated by two semicolons ';'. There must be two and only two semicolons in for..loop statement.

  • Initiliation, condition checking and increment/decrement must be written in ( ) closed bracket, and there must not be ';' semicolon after bracket.

  • If you want to execute only one statement, if condition is true for loop, then it can be given without { } brace brackets. To exeucute more than one statements for true, all the statement block must be written within { } brace bracket.






Statements if condition is true;

Statements if condition is true




Statements if consition is false or when condition is completed.



javascript for statement


Example: The following example shows the use of JavaScript for loop statement.

No = 1

No = 2

No = 3

No = 4

No = 5


  • From the example above, you can read:

  • In for Statement 1st part, variable is defined as 1 before the loop starts (var n=1).

  • Part 2 of for statement defines the condition for the loop to run (n must be less than or equal to 5).

  • Part 3 of for statement increases a value (n++) each time, that is same as n=n+1.


Example: The following example shows the use of JavaScript for loop statement.

no = 50

no = 45

no = 40

no = 35

no = 30

no = 25

no = 20

no = 15

no = 10

Example: The following example shows the use of JavaScript for loop statement.

Sum of numbers from 1 to 10 is = 55


  • This program calculates the sum of numbers from 1 to 10 , and prints that. The program starts by defining two variables x and sum. x is used as an index variable in the for statement (i.e. it is assigned values from 1 to 10) ; sum is used for storing the sum of the 10 numbers.

The for statement

for(x=1 ; x<=10 ; x++)


  • Causes the statement [sum=sum+x] to be executed for x=1,2,3,..,10 . So , every value of x from 1 to 10 is added to sum .The final value of sum is then printed by the document.write statement :


Example: the following example shows the use of for loop statement, Lets suppose if someone offers you Rs. 1,00,00,000/- (Rs. One Crore) in return on 1st day of month you have to pay Rs. 1 for 1st day, Rs. 2 for 2nd day, Rs. 4 for 3rd day and so on, for one month only, check out yourself.

On 1 Day you have to pay Rs. 1

On 2 Day you have to pay Rs. 2

On 3 Day you have to pay Rs. 4


On 31 Day you have to pay Rs. 107374182

Pr.Pg border                                              Next Pg