JavaScript Conditions and Branching Code Structures

Look to the following table for JavaScript control structures you can use in your program code to add branching and looping behavior to your JavaScript programs.



























ElementDescription
if (condition){class="code">

// contentclass="code">

} else {

// more contentclass="code">

} // end if
Executes content only if condition is true.

Optional else clause occurs if condition
is false.
switch (expression)class="code">

case: value;class="code">

//code

break;

default:

//code

}
Compares expression against one or more values. If expression
is equal to value, runs corresponding code.

Default clause catches any uncaught values.
for(i = 0; i < count; i++)class="code">

//code

} // end for
Repeats code i times.
While (condition){class="code">

//code

} // end while
Repeats code as long as condition is true.
Function fnName(paramaters) {class="code">

//code

} // end function
Defines a function named fnName and
sends it parameters. All code inside the function will execute when
the function is called.








dummies

Source:http://www.dummies.com/how-to/content/javascript-conditions-and-branching-code-structure.html

No comments:

Post a Comment