Do while:
As you know if the conditional expression controlling a while loop initially false then the body of the loop will not be executed at all. However, sometimes it is desirable to execute the body of a while loop at least once, even if the conditional expression is false at the beginning. We can say that, there are times while programming with java when you would like to test the conditional expression at the end of the body of loop rather than at the beginning. Fortunately, java supplies a loop that does just that: the do while.
The do while loop always executes its body first (even if the conditional expression is false to begin with) and then checks the conditional expression. It does so because its conditional expression is at the bottom/end of the body of the loop. Its general form is:
do
{
//body of loop
}
while (condition);
Each iteration of this loop first executes body of the loop and then evaluates the conditional expression, controlling the loop. If this condition is true then loop will repeat otherwise, the loop terminates. Remember, a condition must be a Boolean expression.
Java basics, conditional, switch, loops, arrays, methods and inheritance articles and programs.
Search This Blog
UI/UX Design | Web Development | Mobile Application Development
Whether you need UI/ UX design, web development services, or mobile app development services, Qaabil Digitals will be more than happy to help you. We work with top software developers, designers, and project managers. We tailor our services to suit your exact needs. We closely look at your company, listen to your story, and bring about the best ideas and solutions that can help you drive solid results. We don’t just produce work that works. We produce work that matters. Get a quote now Or Talk to us
Saturday, 16 July 2011
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment