iterate with javascript do while loops

Solutions on MaxInterview for iterate with javascript do while loops by the best coders in the world

showing results for - "iterate with javascript do while loops"
Dino
05 Jan 2017
1var myArray = []
2
3
4
5var i = 0;
6while(i < 5){
7    myArray.push(i)
8    i++
9}
10
11
12console.log(myArray);
Emna
14 Jan 2019
1var myArray = [];
2
3var i = 10;
4
5 do {  // The do while loop will always run atleast once before checking the condtion. This will return false and break out of the loop.
6	myArray.push(i);
7    i++;
8} while (i < 5)
9
10console.log(i, myArray);
Max
05 Feb 2019
1var ourArray = []; 
2var i = 5;
3do {
4  ourArray.push(i);
5  i++;
6} while (i < 5); // it will work once and stop looping.
Valerio
08 Aug 2017
1var ourArray = [];
2var i = 0;
3while(i < 5) {
4  ourArray.push(i);
5  i++;
6} // 0 to 4 [ 0, 1, 2, 3, 4 ]
7
8var myArray = [];
9var i = 5;
10while (i  >= 0) {
11  myArray.push(i);
12  i--;
13} // 5 to 0 (reverse) [ 5, 4, 3, 2, 1, 0 ]