JS3 Process Control

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.