instructional systems
Index:
[Session12] JavaScript 2 (Basic syntax, control structure (if, for, etc.))
1 Chapter1
2 Chapter2
3 Chapter3
4 Chapter4
5 Chapter5
Your Location: Home Page  >  [3] Interactive web pages using JavaScript (on condition)  >  [Session12]JavaScript 2 (Basic syntax, control structure (if, for, etc.))  >  Chapter4  >  4.5 Repetition Control Statement 3 (do...while)
Repetition Control Statement 3 (do...while)
[The purpose of this section]
The do while repetition control statement is one of loop control statements that repeat the process until the evaluation expression value is no longer TRUE. However, the difference from the “while statement” and the most outstanding characteristics of the do ...while statement is that it executes do...while at least once before obtaining the evaluation expression value, as shown below.
This section deals with the do...while repetition control statement.

The Basics of do...while Repetition Control Statement

do {
  statement 1; statement 2;...;
} while (evaluation expression value);

Sample 1 (dowhile.html)

Let’s confirm the above in the following sample program.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="ja">
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 <meta http-equiv="Content-Script-Type" content="text/javascript
 charset=utf-8">
 <title>Experiment of do...while</title>
</head>
<body>
<h3> Confirming do...while statement</h3>
 <script type="text/javascript">
 <!--
    k=0;i=0;
    n=25;m=n;
    do {
       i++;
       k=k+i;
       n--;
    } while (n > 0);
    document.write('n=',m,' k=',k);
 //-->
 </script>
</body>
</html>
Copyright (c) Yasuo Musashi 2003, All Rights Reserved