Write a code to demonstrate different type of loop in JAVA.

0

 

Aim: Write a code to demonstrate different type of loop in JAVA.


Source Code:


class HelloWorld {

    public static void main(String[] args) {

        int a = 1;

        int b = 5;

       

        System.out.println("FOR LOOP");

        for(int i = 0 ; i < b ; i++){

            System.out.print("Namaste duniya\n");

        }

       

        System.out.println("WHILE LOOP");

        while(a <= 2){

           

            System.out.println("Namaste duniya");

            a++;

        }

        System.out.println("DO WHILE LOOP");

        do{

            System.out.println("Namaste duniya");

        }

        while(a>b);

       

    }

}

 

 

Result/Output:



Post a Comment

0Comments
Post a Comment (0)