javascript for next code example
Example 1: javascript for loop
var colors=["red","blue","green"];
for (let i = 0; i < colors.length; i++) {
console.log(colors[i]);
}
Example 2: javascript for loop
for (var i; i < 10; i++) {
}
Example 3: loop an array in javascript
let array = ["loop", "this", "array"];
for (let i = 0; i < array.length; i++) {
console.log(array[i]);
}
Example 4: for next loop javasxcrop
for (i = 0; i < 5; i++) {}
Example 5: for loop js
let arr = [];
for(let i = 0; i <= 10; i++){
arr[i] = Math.round(Math.random() * 10);
}
• Result: [3, 1, 1, 2, 3, 9, 5, 6, 6, 8, 5]
• Or
let arr = [];
for(let i = 0; i <= 10; i++){
arr[i] = Math.trunc(Math.random() * 10);
}
Result[7, 6, 0, 2, 4, 8, 7, 5, 5, 6, 5]
Example 6: for loop
Coroutine doThisCoroutine;
int duration = 5
float waitTime = 1
void Awake(){
DoThisCoroutine = StartCoroutine(DoThis());
}
IEnumerator DoThis(){
while (enabled){
for (int x = 0; x < Duration; x++){
print("Doing This!");
yield return new WaitForSeconds(waitTime)
}
}
}