Relatively simple (as with Process Control in Java)
Make a judgment (if statement )
if (condition)
{Execute code when condition is set}
Two Choice one (if...else statement )
if (condition)
{Code executed when condition is set}
Else
{Code executed when the condition is not valid}
Multiple judgments (if.. else nested statements )
if ( condition 1)
{Condition 10% code to execute immediately}
else if ( condition 2)
{Condition 20% code to execute immediately}
...
else if ( condition n)
{The code executed when condition n was established}
Else
{Conditions 1, 2 to n are not immediately executed code}
Multiple options (switch statement )
switch ( expression)
{
Case value 1:
Executing code block 1
Break
Case Value 2:
Executing code block 2
Break ;
...
Case Value N:
Execute code block n
Break ;
Default
Code that executes when the case value is 1 and 2...case value n is different
}
Repeat repeat (forloop )
for (initialize variable; loop condition; loop iteration)
{
Looping statements
}
<script type= "Text/javascript" >
var num=1;
for (num=1;num<=6;num++)//initialization value; loop condition; post-cycle Condition value Update
{document.write ("Remove" +num+ "ball <br/>");
}
</script>
Repeatedly (whileloop )
while (judging condition)
{
Looping statements
}
To go back and forth (Do...while loop )
Do
{
Looping statements
}
while (Judging condition)
<script type= "Text/javascript" >
Num= 1;
Do
{
document.write ("Value:" + num+ "<br/>");
num++; Update condition
}
while (num<=5)
</script>
Exit Loop break
Use the break statement in the while loop to exit the current loop and execute the following code directly.
The format is as follows:
for (initial conditions; judging condition; post-cycle condition value update)
{
if (special case)
{break;}
Loop code
}
Continue circulation Continue
The function of the continue is to simply skip the cycle and the entire loop will continue to execute.
Statement structure:
for (initial conditions; judging condition; post-cycle condition value update)
{
if (special case)
{continue;}
Loop code
}
JS3 Process Control