JS Flow control Statement

Source: Internet
Author: User

Do...while Statement

The Do...while statement is a looping statement that runs first and then judges. In other words, the loop body is run at least once, regardless of whether the condition is satisfied.

var box = 1; If it is 1, execute five times, if it is 10, perform 1 times

do {

alert (box);

box++;

} while (box <= 5); Run first, then judge

for...in Statement

The for...in statement is a precise iterative statement that can be used to enumerate the properties of an object.

var box = {//Create an Object

' Name ': ' Li Tinghui ',//key value pair, left is the property name, the right is the value

' Age ': 28,

' Height ': 178

};

For (var p in box) {//Enumerate all properties of an object

Alert (p);

}

Break and Continue Statement

The break and continue statements are used to precisely control the execution of code in a loop. Where the break statement exits the loop immediately, forcing the statement following the loop body to continue executing. While the continue statement exits the current loop, the loop continues behind.

for (var box = 1; box <=; box++) {

if (box = = 5) break; If box is 5, exit the loop

document.write (box);

document.write (' <br/> ');

}

for (var box = 1; box <=; box++) {

if (box = = 5) continue; If box is 5, exit the current loop

document.write (box);

document.write (' <br/> ');

}

with Statement

The function of the WITH statement is to set the scope of the code to a specific object.

var box = {//Create an Object

' Name ': ' Li Tinghui ',//key-value pair

' Age ': 28,

' Height ': 178

};

var n = box.name; Assigning values from objects to variables

var a = Box.age;

var h = box.height;

The above three-segment assignment can be rewritten as:

With (box) {//Omitted box object name

var n = name;

var a = age;

var h = height;

}

JS Flow control Statement

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.