Java Do While Loop
When we wish to test the exit condition at the end of the loop, we use a do-while loop. The do-while loop always executes its body at least once, because its conditional expression is at the bottom of the loop.
Example:
public class Myclass { public static void main(String[] args) { int num = 9; boolean divisibleBy7 = false; do { System.out.println(num); if (num % 7 == 0) divisibleBy7 = true; num--; } while (divisibleBy7 == false); } }
Output
9 8 7
