How to Implement Do-while Loop in Java


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
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments