1- /*
2- JavaScript Loops
31
42The JavaScript loops are used to iterate the piece of code using for , while , do while or for - in loops . It makes the code compact . It is mostly used in array .
53
64There are four types of loops in JavaScript .
75
8- for loop
9- while loop
10- do-while loop
11- for-in loop
6+ 1 ) for loop
7+ 2 ) while loop
8+ 3 ) do - while loop
9+ 4 ) for - in loop
1210
1311
1412 1 ) JavaScript For loop
@@ -19,35 +17,35 @@ There are four types of loops in JavaScript.
1917 {
2018 code to be executed
2119 }
22- */
20+
2321
2422 for ( var i = 0 ; i <= 10 ; i ++ ) {
2523 document . write ( i + "<br>" ) ;
2624 }
2725
28- /* JavaScript while loop
26+ 2 ) JavaScript while loop
2927
3028 The JavaScript while loop iterates the elements for the infinite number of times . It should be used if number of iteration is not known . The syntax of while loop is given below .
3129
3230 while ( condition )
3331 {
3432 code to be executed
35- } */
33+ }
3634
3735 var i = 1 ;
3836 while ( i <= 15 ) {
3937 document . write ( i + "<br>" ) ;
4038 i ++ ;
4139 }
4240
43- /* JavaScript do while loop
41+ 3 ) JavaScript do while loop
4442
4543 The JavaScript do while loop iterates the elements for the infinite number of times like while loop . But , code is executed at least once whether condition is true or false . The syntax of do while loop is given below .
4644
4745 do {
4846 code to be executed
4947 }
50- while (condition); */
48+ while ( condition ) ;
5149
5250 var i = 50 ;
5351 do {
@@ -56,12 +54,12 @@ There are four types of loops in JavaScript.
5654 }
5755 while ( i <= 52 )
5856
59- /* forEach loop
57+ 4 ) forEach loop
6058
6159 its apply on array whenever you have array you can use foreach loop
62- for each loop by default not change your array but its change on copy of array so original array is same */
60+ for each loop by default not change your array but its change on copy of array so original array is same
6361
64- var sum = 0 ;
62+ var sum = 0 ;
6563 var arr = [ 10 , 18 , 12 , 20 ] ;
6664
6765 arr . forEach ( function myFunction ( element ) {
@@ -70,4 +68,3 @@ There are four types of loops in JavaScript.
7068 } ) ;
7169
7270
73-
0 commit comments