Javascript::Javascript-Control Structures
Control structures
If ... else
if (condition) {
statements
} else {
statements
}
Switch statement
switch (expression) {
case label1 :
statements;
break;
case label2 :
statements;
break;
default :
statements;
}
Actually, break;
is optional. However leaving it out isn't recommended in most cases since otherwise code execution will continue to the body of the next case … :
.
For loop
for ([initial-expression]; [condition]; [increment-expression]) {
statements
}
For ... in loop
This loop goes through all enumerable properties of an object (or elements of an array).
for (slot in object) {
statements involving object[slot]
}
While loop
while (condition) {
statements
}
Do ... while
do {
statements
} while (condition);
..
Javascript::Javascript-Control Structures Related Sites
[READ MORE : Javascript::Javascript-Control Structures] |