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"]; // input array variable
for (let i = 0; i < array.length; i++) { // iteration over input
	console.log(array[i]); // logs the elements from the current input
}

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

// Unity for loop coroutine (repeat something every x seconds for x time)

Coroutine doThisCoroutine; // (Create a coroutine for stopping)
int duration = 5 // (Duration, whatever you want it to be)
float waitTime = 1 // Wait time to iterate in seconds, usually 1

void Awake(){
  
  DoThisCoroutine = StartCoroutine(DoThis()); // Start the coroutine
    
}
    
IEnumerator DoThis(){
  
  while (enabled){ // While the behavior is enabled,
  
    for (int x = 0; x < Duration; x++){ // From zero until 5 incrementing by 1...
    
      print("Doing This!"); // Do whatever...
  	
      yield return new WaitForSeconds(waitTime) // Every second.
  
  	}
  
  }

}

Tags:

Cpp Example