0
What is the simple definitions for kinds of loops?
2 Respuestas
+ 2
--for: Used to iterate the same block a set number of times(2nd statement). Typically used to loop through all values of an array.
--while: Iterates the same block as long as the parentheses statement returns true. Typically used to operate on the value of the statement that is being tested.
--do...while: Same as while, but iterates the block at least once, even if the statement returns false.
<EXAMPLES>
var arr=[1,2,3];
for(i=0;i<arr.length-1;i++){
if(arr[i] === 3){
alert("I is 3");
}}//iterates 3 times, since arr.length-1 = 2(0,1,2)
-----
var z=10;
while(z !==5){
z--;
}alert(z);//alerts 5
-----
var x= 5;
do{
x--;
} while (x>10)
alert(x);//alerts 4
+ 1
kind of repeat