Language syntax
Java do-while statement
Use a post-test loop for work that needs an initial attempt. Include the trailing semicolon.
Formal Syntax & Structure
java syntaxjava
do { statements } while (condition);Working Example
Example Snippetjava
public class Main { public static void main(String[] args) { int attempts = 0; do { attempts++; } while (attempts < 2); System.out.println(attempts); }}