“JavaScript fait pendant” Réponses codées

javascript pendant

var i=0;
while (i < 10) {
	console.log(i);
	i++;
}
//Alternatively, You could  break out of a loop like so:
var i=0;
while(true){
	i++;
	if(i===3){
		break;
	}
}
Grepper

tandis que Loop JavaScript

while (condition) {
	// code
}

// example
let index = 0;

while (index < 10) {
    // code
    index++;
}

//  enjoy :)
Odd Octopus

tandis que vs faire pendant que javascript

// while vs do...while loops

/* while loops: check condition first. If true, execute code. */
let i = 0; 
while (i < 5) {
  console.log(i); // 0 1 2 3 4
   i += 1;
}

/* do-while loops: execute code at least once even if condition is false. 
Then check condition. If true, continue executing code. */
let j = 6;
do {
  console.log(j); // 6
    j += 1;
} while (j < 5);
Intra

pendant et faire pendant la boucle en javascript

var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
//  while loop
 let j= 0;
 while(j < arr.length)
 {
     console.log(arr[j]);
     j++;
 }

//do-while loop
 let k=0;
 do{
     console.log(arr[k]);
     k++;
 }
 while(k < arr.length);
kinjal suryavanshi

JavaScript fait pendant

let arr = ['jan', 'feb', 'mar', 'apr', 'may'], i = 0;
// do something at least 1 time even if the condition is false
do{
	console.log(arr[i]);
	i++;
}while(arr.includes('dec'));
// output: jan 
Felipe Lullio

JavaScript fait pendant

/*
`do while` is essentially like the basic `while` statement
except for one key difference, the body is always executed
at least once.

Syntax:
do {
	body
} while (condition);

This is generally only useful if you need the body to run
at least once, before the condition is checked.
*/

let i = 10;
do {
	console.log(i);
	i--;
} while (i > 0);

/*
Outputs:
10
9
8
7
6
5
4
3
2
1
*/
MattDESTROYER

Réponses similaires à “JavaScript fait pendant”

Questions similaires à “JavaScript fait pendant”

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code