FOR LOOP
For loop is also similar to the while loop. In while loop the we have to give the initialization, Condition, Increment/ Decrement in a multiple line but in for loop we can give these all things in a single line .
SYNTAX
for(initialization, condition, increment/decrement){
-----------
-----------
}
Example Program
for(let i=1;i<=5;i++){
console.log(i);
output:
1
2
3
4
5
Not only compulsory we should have to give in the single line we can also give like this also
let i=1;
for( ; i<=5; )
{
console.log(i);
i++;
}
output:
1
2
3
4
5
Both the for and while are called as aentry check
*do while *
The do...while statements combo defines a code block to be executed once, and repeated as long as a condition is true.
SYNTAX
do{
------
------
}while(condition)
EXAMPLE PROGRAM
let i=5;
do{
console.log("Hello");
i++;
}while(i<5)
output: Hello
The do while loop is called as a exit check
Top comments (0)