O'Reilly logo

JavaScript™ 1.5 by Example by Kathie Kingsley-Hughes, Adrian Kingsley-Hughes

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Iteration Statements

An iteration is the repetition of a sequence of statements either

  • A specified number of times

  • Until a condition is met

Four iteration statements are available:

  • The do ... while statement

  • The while statement

  • The for statement

  • The for ... in statement

Each of these statements performs a slightly different task, but each is a useful statement to learn how to use.

The do ... while Statement

The do ... while statement runs a statement or a block of statements and then repeats the whole process until the condition expression is false. An example will clarify this:

<script language="JavaScript">
<!-- Cloaking device on!
var x = 1
do
{
++x;
alert(x);
}
while (x < 10);
// Cloaking device off -->
</script>

The previous code has a variable, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required