seven, Circular Statements
1.While
Grammar:
while (exp) { //statements;}
Description
while (variable <= End Value) {
Cases:
var i=0; while (i<=9) { // use a loop to output 9 photos on the page document.write (' ); I+ +; }
2. do...while
The Do...while function is the same as while, except that the do...while is executed after the execution, while Vice Versa.
syntax:
do { //statements;} while (condition);
Description
do { while (variable <= end value);
Cases:
var i=0; do { // using loops to output 9 photos document.write (' " ); I+ +;} while (i<=9);
3.for Loop Statement
Grammar:
for (initial; expression; post-loop-expression) { //}
Description
for (variable = start value; variable <= end value; variable = variable + step value) {
Cases:
4. Break statement and Continue statement
The break statement can exit the Loop immediately;
the continue statement simply exits the current loop;
Cases:
for (var i = 1; i < i++) { if(i = = 4) { continue// Exit the loop, and the remaining loop continues to execute } if(i = = 7) {break; // terminates the loop, after which the remaining loops are not executing }
seven, function
description: A function is a set of statements that completes a function, defined by a keyword function + function name + a set of parameters; function in a fixed
After righteousness can be repeated calls, often used to write functions as a function, the use of functions can make the structure of the code more clear.
1. Basic Syntax:
function funname (arg0, arg1, ... argN) { //}
Use of 2.return
Return a value from a function using the return statement
function sum (num1, num2) { return num1 +var s = Sum (1, 2); alert (s); // result is 1+2=3;
Attention:
1. Any code that is behind the return statement will never be executed!
2. In javascript, you don't have to specify a return value!
3. When defining the parameters of a function, if the function is called without passing arguments, it does not give an error, but it can be judged in the function whether there is a pass-in argument, for example:
if (variable = = 'undefined ' | | variable = = Null) { variable= ' 1 '; //can give him a default value }
JavaScript Beginner Chapter _4 (loops and Functions)