Use a For loop when the number of times the script has been run has been determined.
Grammar:
for
(variable = start value; variable <= end value; variable = variable + step value) { code to be executed}
Instance:
Explanation: The following example defines a cyclic program in which the starting value of I is 0. Each time the loop is executed, the value of I accumulates 1, and the loop runs until I equals 10.
Note: The step value can be negative. If the step value is negative, you need to adjust the comparison operator in the for Declaration.
for (i=0;i<=10;i++){
//javaScript的输出
document.write("<br />")// }
The while loop takes advantage of a while loop to loop through code when the specified condition is true.
The Do While loop uses the Do...while loop to loop through code when the specified condition is true.
This loop is executed at least once, even if the condition is false. This is because the statement executes before the condition is validated.
While loop
The while loop is used to loop code execution when the specified condition is true.
Grammar:
while
(Variable <= end value) { code to be executed}
Note: In addition to <=, you can also use other comparison operators.
Instance:
Explanation: The following example defines a cyclic program with a starting value of 0 for the parameter I of the Loop program. The program runs repeatedly until I is greater than 10. The step value of I is 1.
while (i<=10){document.write("The number is " + i)document.write("<br />")i=i+1} </script></body>
Do...while Cycle
The Do...while loop is a variant of the while loop. The loop program executes the code one time at the first run and then continues the loop when the specified condition is true. So, so to speak, the Do...while loop is to execute at least one of the code, even if the condition is false, because conditional validation occurs after the code in it executes.
Grammar:
do
{ code to be executed} while
(Variable <= end value)
Instance:
do {document.write("The number is " + i)document.write("<br />")i=i+1}while (i<0) </script></body>