do while循环与while循环相似,只是它在执行语句之后检查条件,因此是Exit Control Loop的一个示例。
句法:
do { statements.. } while (condition);
流程图:
// Java program to illustrate do-while loop class dowhileloopDemo { public static void main(String args[]) { int x = 21; do { // The line will be printed even // if the condition is false System.out.println("Value of x:" + x); x++; } while (x < 20); } }
输出:
Value of x: 21