Execute block of code. After that check if condition is still true, if still true, DO AGAIN.

do while loop java

The Do-While-Loop is, like the name shows, related to the While-Loop. Difference:

  • WHILE – you check condition if true run code
  • DO-WHILE – you first run and then check the condition

do while loop java

do{  
//code to be executed  
}while(true);  

For Example:

package P;

import java.io.PrintStream;

public class C {

	PrintStream out;

	C () {
		out = new PrintStream(System.out);
	}

	void start() {
	do{ 
		out.println("infinitive Do-While-Loop"); 
	} while(true);
	
	}

	public static void main(String[] argv) {
		new C().start();
	}
}

Output:

infinitive do while loop
infinitive do while loop
infinitive do while loop

(followed by Ctrl-Z (Windows) or Ctrl-D (Linux and OSX).)