Do-While Statements

Submitted by: 

This page will teach you how to use the Do-While statements in Java.

It is fairly important you understand the While Statement before reading this tutorial page. It can be found on the main Java Tutorial Thread page.

What is a Do-While Statement?
A Do-While Statement is very similar to a While Statement, with one exception. The conditions that require to be true for the code to re-execute are checked at the bottom of the loop which therefore means the while script is executed at least once (before the first check).


  1. boolean thisTrue = false;
  2. do {
  3. System.out.println("Executing...");
  4. }while (thisTrue);
  5. thisTrue = true;
  6. do {
  7. System.out.println("Executing...");
  8. }while (thisTrue);

The above code executes the output once while the boolean "thisTrue" is false, it then changes to true and outputs continuously. The output given was:

	{Infinite Loop Starts Here}


Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.