for(first; second; third);
Inside the parentheses, the semicolon is the delimiter, not the end of the line.
first – any instruction that the machine will execute once at the very beginning of the loop, for example, you can initialize a variable.
second – a condition similar to the conditions from the while loop; e.g. cat<2.
third – essentially the same as first; there may be a change in the counter; this part is executed each time at the end of the iteration of the loop.
Any of the three parts in the for loop can be omitted, it could look like this:
for( ; second; third);
for(first; ;third); etc.
To make the for loop similar to the while loop, it can be represented as follows:
for( ; cat<11; );
Those. if the second part of the for loop is empty, then the loop will be executed indefinitely.
Task: Raise a number to the power of a number using a for loop.
document.write((result=result*num) + “<br \/>”);