In this example we will show how to use do-while loop in Java.
Source Code
package com.beginner.examples;
public class DoWhile {
public static void main(String[] args) {
int k = 0;
do {
System.out.println(k);
k++;
}
while (k < 3); // end condition
}
}
Output:
0
1
2