[Solved] How to use a do-while loop in Java? [closed]


This is the do-while equivalent of your program.

In do while the code inside the {} block executed at least once before checking the condition. And the condition is checked after execution of that block.

For Complete Tutorial On do-while loop, refer this link

Structure:

       do{
          //do here
       }while(booleanExpression);

This is your do-while equivalent: See comments in the code

    class Tester
    {
       public static void main (String args[]){

          int i=1;
          do{                          //block started with out checking condition
         System.out.print("\n");     
         int j=1;
         do {                       //inner loop starts
           System.out.print(j);
           j++;
           }while(j<=i);             //condition check for inner loop
           i++;
          }while(i<=4);             //condition check for outer loop
        }
    }

0

solved How to use a do-while loop in Java? [closed]