Loop control
① for Loop
for (var i =0;i<; i++)
{Document.writeln (" Hello <br>");
}
② While first judge to execute the statement again
while (i< 10)
{Document.writeln ("hello<br>");
i++;
}
③ does while performing a second judgment
var i=0;
Do
{Document.writeln ("Ni hao <br>");
i++;
}while (I<10);
① calculates 1+2+3. ..... N
<HTML><Head><Scripttype= "Text/javascript">//Calculate calculation 1+2+3 .... NvarN=Window.prompt ("Please enter an integer"); n=parseint (n);varRes=0; for (varI=1; I<=N; I++) {res+=i;} Document.writeln ("The result is"+res);</Script></Head><Body></Body></HTML>
② calculation 1! +2! +3! +... n!
<HTML><Head><Scripttype= "Text/javascript">//Calculate 1!+2!+....+n!varN=Window.prompt ("Please enter an integer"); n=parseint (n);varRes=0;varTemp=1; for (varI=1; I<=N; I++ ){ for (varJ=1; J<=i;j++) {Temp*=J; } Res+=temp; Temp=1;} Document.writeln ("The result is"+res);</Script></Head><Body></Body></HTML>
A very useful tool.
In IE8 , we can use the tool to debug the js code, especially if the page is more complex
Disable script debugging in ie- tools -internet options - Advanced
Click Tools- developer Tools
F11: One sentence to execute, if a function is encountered, then jump into the function, then a sentence to execute.
F10: by procedure, when a function is encountered,F10 executes the entire function as a statement without jumping into execution
Shif+f11 jumps out of a function.
Local variables: You can see the change of the variable
Breakpoints: You can see the breakpoint condition, you can set breakpoints, cancel breakpoints.
Install plug-in firebugwith firefox browser, set breakpoints, step-by-line test
Learn js to learn to do js Debugging.
In the case of complex pages, it is important to block and debug sections.
JS three-Process Control (sequential flow, branch control, loop control), JS mode skills