-
Notifications
You must be signed in to change notification settings - Fork 2
Java Loops Types Do While
The do while
is very similar to the while
loop in the way it works, but is exit controlled (unlike the for
and while
loops which are entry controlled), that is, the truth value of its expression
is evaluated after the execution of Statements
.
do
{
// Statements
}
while (expression);
This kind of loop is particularly useful if you want your Statements
to be executed at least once, irrespective of what expression
evaluates to. You want to do this if you are initializing a variable inside your loop and plan on using its value later.
int iter_DoWhile = 20;
do
{
System.out.print (iter_DoWhile + " ");
// Increment the counter
iter_DoWhile++;
}
while(iter_DoWhile < 10);
System.out.println ("iter_DoWhile Value: " + iter_DoWhile);
Output:
20
iter_DoWhile Value: 21
🚀 Run Code
Learn to code and help nonprofits. Join our open source community in 15 seconds at http://freecodecamp.com
Follow our Medium blog
Follow Quincy on Quora
Follow us on Twitter
Like us on Facebook
And be sure to click the "Star" button in the upper right of this page.
New to Free Code Camp?
JS Concepts
JS Language Reference
- arguments
- Array.prototype.filter
- Array.prototype.indexOf
- Array.prototype.map
- Array.prototype.pop
- Array.prototype.push
- Array.prototype.shift
- Array.prototype.slice
- Array.prototype.some
- Array.prototype.toString
- Boolean
- for loop
- for..in loop
- for..of loop
- String.prototype.split
- String.prototype.toLowerCase
- String.prototype.toUpperCase
- undefined
Other Links