+ 1
What is the for loop process?
<script> var x=0; for(var i=0;i<5;i++){ x++; break } console.log(x) </script>
4 Answers
+ 9
 ⢠Skipping parts ;)
Any part of 'for' can be skipped.
For example, we can omit 'begin' if we donât need to do anything at the loop start.
let i = 0; // we have i already declared and assigned
for ( ; i < 3; i++) { // no need for "begin"
   alert( i ); // 0, 1, 2
}
We can also remove the 'step' part:
let i = 0;
for ( ; i < 3; ) {
   alert( i++ );
}
The loop became identical to while (i < 3).
We can actually remove everything, thus creating an infinite loop:
for ( ; ; ) {
   // repeats without limits
}
Please note that the two 'for' semicolons ; must be present, otherwise it would be a syntax error.
+ 8
 ⢠The For Loop
Itâs the most basic of loops in JavaScript and is quite versatile.
for (i = 0; i < 10; i++) {
   // do something
}
Our for loop consists of three statements, one that is executed before our loop starts ( i = 0 ), one that defines how long our loop should run ( i < 10 ), and one that is executed after each loop ( i++ ).
In this example, we are setting i = 0 before our loop starts. We will continue to loop as long as i < 10, and each iteration of the loop will increase i by one. Finally, within our brackets is the code that will be run on each iteration of the loop.
+ 3
This loop can only run 1 iteration because of the break statement inside. X get equal to 1 because if the incrementation and then finally reach out the loop scope and print 1 to the console.
+ 2
Thanks guys đ