If conditional statement syntax:
if (condition) {
statements;
}
Understanding: In parentheses are the conditional parameters, the statements executed in curly braces.
Example code:if (1>2) {
Alert ("The world has gone mad!")
}
While loop statement syntax:
Initialize:
while (condition) {
statements;
}
Understanding: While loops are commonly known as loops, syntax is consistent with if, and different points are. When the condition evaluates to true, the statement in the curly braces repeats the loop. So the statement in the while Loop has a statement that affects the loop condition.
Example code:var count=1;
while (count<11) {
alert (count);
count++; Count is added, Loop 10 times after the condition evaluates to False, the loop terminates.
}
Do...while Loop statement Syntax:
Initialize:
do{
statements;
}while (condition);
Understanding: The difference between the Do...while loop and the while loop is that the statement in the curly braces is executed once, regardless of whether the condition evaluates to TRUE or FALSE.
Example code:var count=1
do{
alert (count);
count++
}while (COUNT<11); After looping 10 times, even if the value of Count is 11, the value of the conditional statement is false, and the statement in the curly braces is still executed once.
For Loop statement syntax:
For (initial condition; test condition; alter condition) {
Statements:
}
Understanding: The For loop differs from the above loop; It writes all the loop-related statements in parentheses. The benefit of this is to make the loop control structure clearer.
Example code: For(var count=1; count<11; count++) {
Alert (count)
}
Summary of JavaScript syntax for looping statements