The control structure Switch in Js uses varday12; // switch (day) {// case1: // document. write (& quot; Monday & quot;); // break; // case2: // document. write (& quot; Tuesday & quot;); // break; // case3: // document. w
Control Structure in Js
Switch usage
Var day = 12;
// Switch (day ){
// Case 1:
// Document. write ("Monday ");
// Break;
// Case 2:
// Document. write ("Tuesday ");
// Break;
// Case 3:
// Document. write ("Wednesday ");
// Break;
// Case 4:
// Document. write ("Thursday ");
// Break;
// Case 5:
// Document. write ("Friday ");
// Break;
// Case 6:
// Document. write ("Saturday ");
// Break;
// Case 7:
// Document. write ("lifecycle 7 ");
// Break;
// Default: document. write ("enter a number between-7 ");
//}
The difference between using and without a break is as follows: www.2cto.com
/// Define the three variables of the year, month, and day, and assign values to calculate that the date is the day of the current year.
// Var year = 2012; // year
// Var month = 5; // month
// Var day = 12; // day
// Var days = 0;
// Switch (month-1 ){
// Case 11: days + = 30;
// Case 10: days + = 31;
// Case 9: days + = 30;
// Case 8: days + = 31;
// Case 7: days + = 31;
// Case 6: days + = 30;
// Case 5: days + = 31;
// Case 4: days + = 30;
// Case 3: days + = 31;
// Case 2:
// If (year % 4 = 0 & year % 100! = 0) | (year % 400 = 0 )){
// Days + = 29
//
//}
// Else {
//
// Days + = 28;
//}
//
// Case 1: days + = 31;
//}
// Days + = day;
// Document. write (year + "year" + month + "month" + day + ", which is the" + days + "day" of this year ");
For Loop usage:
For (a = 1; a <10; a ++ ){
// Document. write ("");
//}
Use of While and do while
// N = 1;
// While (n <= 10 ){
// N ++;
//}
//// Do while is the first execution in the judgment
// M = 9;
// Do {
// Document. write ("m ");
//}
Author: Aweijun360