280 likes | 554 Views
JavaScript Tutorial 4 - Decision Making with Control Structures and Statements . 2. Tutorial 4B Topics. Section B - Repetitionwhile statementsdowhile statementsfor statementsforin statementswith statementscontinue statements. JavaScript Tutorial 4 - Decision Making with C
E N D
1. JavaScript Tutorial 4 - Decision Making with Control Structures and Statements 1 Tutorial 4Decision Making with Control Structures and Statements Section B - Repetition
2. JavaScript Tutorial 4 - Decision Making with Control Structures and Statements 2 Tutorial 4B Topics Section B - Repetition
while statements
do…while statements
for statements
for…in statements
with statements
continue statements
3. JavaScript Tutorial 4 - Decision Making with Control Structures and Statements 3 Repetition Repetition
The if, if…else and switch statements select only a single branch of code to execute, then continue to the statement that follows
Loop statements
Repeatedly execute a statement or a series of statements while a specific is true or until a specific condition becomes true
4. JavaScript Tutorial 4 - Decision Making with Control Structures and Statements 4 Repetition while Statements
Used for repeating a statement or a series of statements as long as a given conditional expression evaluates to true
Typically uses a counter to keep track of iteration
Syntax
while (conditional_expression) {
statement(s);
}
5. JavaScript Tutorial 4 - Decision Making with Control Structures and Statements 5 Repetition while Statements
Example:
var count = 1;
while (count <= 5) {
document.writeln(count);
++count;
}
document.writeln(“You have printed 5 numbers.”);
6. JavaScript Tutorial 4 - Decision Making with Control Structures and Statements 6