I. Circular statements
Features: the same thing can be done repeatedly
1.while (conditional Statement/boolean) {
Code blocks that are repeatedly executed
}
Two ways to Do while
var a= prompt ("please Enter the first number");
var b= prompt ("please Enter a second number");
var i =a>b? a:b; Three-mesh Operation Method
While (i%a!==0 | | i%b!==0) {
i++;
// }
While (true) {
If (i%a!==0 && i%b!==0) {
Break
}
else{
i++;
}
}
Console.log (a + ' and ' +b+ ' least common multiple number "+i);
Note: the loop has to end, or it's a Bug.
Practice One: 1+2+3...+99+100;
var a = 1;
var B = 0;
While (a<=100) {
b = A + b;
a++;
}
Alert (b);
Exercise two: Login user name and password
var a = prompt ("please Enter user name");
var b = Prompt ("please Enter password");
While (a!= "1" | | b!= "0") {
Alert ("user name or password is incorrect");
A = prompt ("please Enter user name");
b = Prompt ("please Enter password");
}
Alert ("login successful");
Exercise Three: 1+2-3+4-5+...-97+98-99+100
var i = 2;
var B = 1;
var he=1;
While (i<=100) {
he=he+b*i;
i++;
b=-b;
}
Alert (he);
2. Terminate loop break: terminates the entire while statement
Terminate loop with break with if else
var a = prompt ("please Enter user name");
var b = Prompt ("please Enter password");
While (true) {
If (a== "1" && b== "0") {
Alert ("login successful");
Break
}
else{
Alert ("user name or password is incorrect");
A = prompt ("please Enter user name");
b = Prompt ("please Enter password");
}
}
3.continue: End the loop now and start the next cycle
var i=1;
While (i<=5) {
If (i===3) {
i++;
continue;}
Console.log (i);
i++;
}
4.do while:
The same as while, the only difference: while the first judgment to do;
do{
Block of code to loop execution}
While (conditional Statement/boolean)
Execution Process:
When the code executes from top to bottom, it encounters the code that executes once after doing, and then makes a judgment by the while, if the judgment passes then executes once, and if it does not, it ends the loop immediately.
do{
var a = prompt ("please Enter user name");
var b = Prompt ("please Enter password");
}
While (a!= "1" | | b!= "0")
Alert ("login Successful")
5.for loop:
Function: used to perform loops
Code: for (var i =0;boolean expression; i++) {}
When the code is executed from the top to the next, the code declares the variable I and assigns the value i, will determine the var i = 1 semicolon after the judgment, to determine whether I is less than or equal to 100, execute the following loop code, when the following code executes, and then back to execute i++.
var he = 0;
for (var i = 1; I <=; i++) {
he = he + i;
}
Alert (he)
13 of the class: from 1 times to 13
Number of daffodils = number of cubes on hundred + 10-digit cubic + single-digit cubic
Prime Number: two variables--double variables
Two. Complex Data types:
Summary: the data types in JS are divided into two main categories:
Simple Data type: string,number,boolean,undefined
Complex Data type: null,array,object,function
Heap and stack are computer memory, in general, simple data types are stored in the stack, complex data types are stored in the heap
A simple data type corresponds to a value type
A complex data type corresponds to a reference type
1. Object objects;
Create object: var a = object ();
A.XM = "zhao";
A.chengji = 99;
object property additions: points: official name attribute
2. Array of arrays
Creation of the array: var a = array ();
var a = Array ();
a[0] = 81;//the number in parentheses is called subscript
a[1] = 82;
a[3] = 92;
Alert (a[1]); Array values
Alert (a.length);//output 3
Note the Point:
A) The JS array is an infinitely large container, and in Java the array can define the Length.
B) elements can be arbitrarily added: the number is unlimited, the data type is not limited (weak language).
C) element subscript is 0 start
The length property of the array: the lengths of the exponential groups.
Array convenience: All arrays can be output at once
For (var I=0;i<a.length;i++) {
Console.log (a[i]); All arrays of output a
}
A string can also be seen as an array
var a = "abc";//can be thought of as an array of element a, b, c elements
3. Function founction:
Defined:
Role: used to encapsulate a number of frequently used code
structure: function name () {}
Call: function ()
Function A (formal parameter) {
Console.log ("i want to eat hotpot");
Console.log ("i have to eat ice cream");
}
A (actual parameter);
A ();
A ();//browser appears 3 times
When creating a function, the parameter after the function name is called formal parameter (formal Argument)
When the function is called, the arguments following the function name are called arguments (actual arguments)
The return value of the Function:
The data following the return is called the return value of the Function.
In general, if there is no return, then this function defaults back to undefined
Js's loop, complex operator