Article From:https://www.cnblogs.com/laber/p/9967660.html

I.Definition of statement

Types of statements

Two.If sentence

if Sentences are conditional judgement sentences, which have three formats:

  1. if () sentence;
    var laber = 100;
    if (laber< 50) {
        alert('laberGreater than 50');
        alert('Anyway, I can be executed!');//Include and execute a compound statement after judgment with a compound statement
    }
  2. if () { sentence;} else { sentence;}

    var laber= 100;
    if (laber > 50) {
        alert('laberGreater than 50');//If true, execute this block of code
    } else {
        alert('laberLess than 50');//If false, execute the block of code
    } 
  3. if () { sentence;} else if () { sentence;} … else { sentence;}

    var laber = 100;
    if (laber >= 100) {                        //If conditions are met, no branch will be executed
        alert('A ');
    } else if (laber>= 90) {
        alert('B ');
    } else if (laber >= 80) {
        alert('C ');
    } else if (laber >= 70) {
        alert('Ding ');
    } else if (laber >= 60) {
        alert('Pass');
    } else {                                //If none of the above is satisfied, the output will fail.
        alert('Fail);
    }

Three.switch sentence

switch is a multi-condition judgment, which is used for the comparison of multiple equal values.

var laber = 1;
switch ( laber) {                            //Multiple values used to determine box equivalence
    case 1 :
        alert('one');
        break;                        //break;Used to prevent sentence penetration
    case 2 : 
        alert('two');
        break;
    case 3 : 
        alert('three');
        break;

    default :                            //It's equivalent to else in the if statement.
        alert('error');
}

Four.do…while sentence

do…while sentence is a kind of circulating sentence which runs first and judges later. That is to say, no matter whether the condition is satisfied or not, run the loop at least once.

var laber = 1;                            //If it's 1, execute five times, if it's 10, execute one time
do {
    alert(laber);
    laber++;
} while (laber<= 5);                        //Run once, then judge

Five.while sentence

while

var laber = 1;                            //If it is 1, execute five times, if it is 10, do not execute
while (laber<= 5) {                        //First judge, then execute
    alert(laber);
    laber++;
}

Six.for sentence

for

for (var laber = 1; laber <= 5 ; laber ++) {        //The first step is to declare the variable var laber = 1.
    alert(laber );                                  //The second step is to judge laber< = 5
}                                                   //Step 3, alert (laber)
                                                    //The fourth step, laber + +
                                                    //Step 5, come back from step 2 until you judge it to be false

Seven.for…in sentence

for…in sentence is a precise iteration sentence, which can be used to enumerate the attributes of objects.

var laber = {                            //Create an object
    'name' : 'moxiaobo',                    //Key-value pairs, attribute names on the left and values on the right
    'age' : 28,
    'height' : 178
};
for (var p in laber) {                        //List all attributes of an object
    alert(p);
}

Eight.breakcontinue sentence

breakcontinue statement is used to precisely control the execution of code in a loop. Among them,break sentence will immediately withdraw from the loop, forcing the execution of the sentence after the loop. andcontinue sentence exits the current cycle and continues the following cycle.

for (var laber = 1; laber <= 10; laber++) {
    if (laber == 5) break;                        //If laber is 5, exit the loop
    document.write(laber );
    document.write('<br />');
}

for (var laber = 1; laber <= 10; laber++) {
    if (laber == 5) continue;                    //If laber is 5, exit the current loop
    document.write(laber );
    document.write('<br />');
}

Nine.with sentence

with sentence is to set the scope of the code to a specific object.

var laber = {                                //Create an object
    'name' : 'moxiaobo',                        //Key value pair
    'age' : 28,
    'height' : 178
};

var n = laber.name;                            //Assignment of values from objects to variables
var a = laber.age;
var h = laber.height;

The above three assignment operations can be rewritten as follows:with (laber) {                                //The laber object name is omitted
    var n = name;
    var a = age;
    var h = height;
}