Java Reference
In-Depth Information
Iteration Statements
Nashorn supports five types of iteration statements:
while Statement
The
do-while Statement
The
for Statement
The
for..in Statement
The
for..each..in Statement
The while , do-while , and for statements in Nashorn works the same as in Java.
I will not discuss them in detail because as a Java developer you know how to use them.
The following code demonstrates their use:
The
// Print first 3 natural numbers using the while,
// do-while, and for statements
var count;
print("Using the while statement...");
count = 1;
while (count <= 3) {
print(count);
count++;
}
print("Using the do-while statement...");
count = 1;
do {
print(count);
count++;
} while (count <= 3);
print("Using the for statement...");
for(var i = 1; i <= 3; i++) {
print(i);
}
 
Search WWH ::




Custom Search