Js Tut
Js Tut
8
JavaScript: Control
Statements II
OBJECTIVES
In this chapter you will learn:
The essentials of counter-controlled
repetition.
To use the for and do while repetition
statements to execute statements in a
program repeatedly.
To perform multiple selection using the
switch selection statement.
To use the break and continue program-
control statements.
To use the logical operators.
8.1 Introduction
8.2 Essentials of Counter-Controlled Repetition
8.3 for Repetition Statement
8.4 Examples Using the for Statement
8.5 switch Multiple-Selection Statement
8.6 do while Repetition Statement
8.7 break and continue Statements
8.8 Labeled break and continue Statements
8.9 Logical Operators
8.10 Summary of Structured Programming
8.11 Wrap-Up
8.12 Web Resources
8.1 Introduction
• The techniques you will learn here are applicable
to most high-level languages, including
JavaScript.
Fig. 8.2 | Counter-controlled repetition with the for statement (Part 2 of 2).
If none of the
case labels
are matched,
execute the
default
actions
• do…while statement
– tests the loop-continuation condition after the loop body
executes
– The loop body always executes at least once
Fig. 8.11 | Using the break statement in a for statement (Part 2 of 2).
Fig. 8.12 | Using the continue statement in a for statement (Part 2 of 2).
Fig. 8.14 | Labeled continue statement in a nested for statement (Part 2 of 2).
expression !expression
false true
true false
Fig. 8.23 | Repeatedly applying Rule 2 of Fig. 8.21 to the simplest flowchart.